#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define NAME "tree"
const int N = 3e5 + 10;
const int INF = 1e9;
int n, t, l[N], r[N], a[N], b[N], mn[N];
bool fail;

void dfsPush(int v) {
    if (l[v] == -1)
        l[v] = n++;
    else
        dfsPush(l[v]);

    if (r[v] == -1)
        r[v] = n++;
    else
        dfsPush(r[v]);
    a[l[v]] = a[v];
    a[r[v]] = -1;
}

void dfs(int v, int mxval) {
    if (l[v] == -1 && r[v] == -1) {
        if (a[v] == -1) a[v] = mxval;
        mn[v] = a[v];
        return;
    }
    if (r[v] != -1) {
        dfs(r[v], mxval);
        if (a[v] == -1)
            a[v] = mn[r[v]] - 1;
    } else if (a[v] == -1) a[v] = mxval;
    if (l[v] != -1) {
        dfs(l[v], a[v] - 1);
        mn[v] = mn[l[v]];
    }
}


pair <int, int> dfsCheck(int v) {
    if (v == -1)
        return make_pair(INF, -INF);
    pair <int, int> ret = make_pair(a[v], a[v]);
    pair <int, int> lef = dfsCheck(l[v]);
    pair <int, int> rig = dfsCheck(r[v]);
    ret.first = min(ret.first, lef.first);
    ret.second = max(ret.second, rig.second);
    if (r[v] != -1 && a[v] >= rig.first || l[v] != -1 && a[v] <= lef.second || a[v] < 0 || a[v] > INF)
        fail = true;
    return ret;
}

int main() {
    freopen(NAME".in", "r", stdin);
    freopen(NAME".out", "w", stdout);
    scanf("%d%d", &n, &t);
    memset(l, -1, sizeof l);
    memset(r, -1, sizeof r);
    int oldn = n;
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d", &l[i], &r[i], &a[i]);
        --l[i];
        --r[i];
    }
    int root = 0;
    dfsPush(root);
    a[root] = t;
    dfs(root, INF);
    dfsCheck(0);
    if (fail)
        printf("-1");
    else {
        for (int i = 0; i < oldn; ++i)
            b[i] = a[r[i]];
        for (int i = 0; i < oldn; ++i)
            printf("%d ", b[i]);
    }
    return 0;
}
