#include <bits/stdc++.h>
using namespace std;

#define TASK "tree"

int n, t;
vector <int> l, r, a;
vector <int> ans;

void traverse(int v, int val)
{
	if (v != -1) traverse(l[v], a[v]);
	ans.push_back(val);
	if (v != -1) traverse(r[v], -v);
}

void solve()
{
	cin >> n >> t;
	l.resize(n);
	r.resize(n);
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i] >> a[i];
		--l[i]; --r[i];
	}
	traverse(0, t);

	int last = 0;
	vector <int> p(n);
	for (int i = 0; i < (int)ans.size(); i++) {
		int x = ans[i];
		if (x <= 0) {
			last = p[-x] = last + 1;
		} else {
			if (x <= last) {
				cout << "-1\n";
				return;
			}
			last = ans[i];
		}
	}
	
	for (int i = 0; i < (int)p.size(); i++) cout << p[i] << " "; cout << endl;
}

int main()
{
	freopen(TASK ".in", "r", stdin);
	freopen(TASK ".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}
