int n, tot, a[maxn], b[maxn], ch[maxn][2], siz[maxn]; ll k, w[maxn];
intmain(){ scanf("%d%I64d", &n, &k); for (int i = 2; i <= n; i++){ int f; ll x; scanf("%d%I64d", &f, &x); w[i] = w[f] ^ x; } for (int i = 1; i <= n; i++) a[i] = b[i] = 1; ll ans = 0; for (int t = 61; t >= 0; t--) { for (int i = 1; i <= tot; i++) ch[i][0] = ch[i][1] = siz[i] = 0; tot = 0; ll s = 0, flag = 0; for (int i = 1; i <= n; i++) { int b = w[i] >> t & 1; if (ch[a[i]][b]) a[i] = ch[a[i]][b]; else a[i] = ch[a[i]][b] = ++tot; siz[a[i]]++; } for (int i = 1; i <= n; i++) { s += siz[ch[b[i]][w[i] >> t & 1]]; } if (s < k) k -= s, flag = 1, ans += 1ll << t; for (int i = 1; i <= n; i++) { b[i] = ch[b[i]][(w[i] >> t & 1) ^ flag]; } } printf("%I64d", ans); return0; }