cin >> n >> k; for (int i = 2; i <= n; ++i) { int x; ll y; cin >> x >> y; w[i] = w[x] ^ y; } for (int i = 1; i <= n; ++i) a[i] = b[i] = rt; for (int o = 61; ~o; --o) { top = o & 1 ? 1 : n + 1; for (int i = 1; i <= n; ++i) { int &p = a[i], d = w[i] >> o & 1; if (!T[p].ch[d]) { T[++top].clear(); T[p].ch[d] = top; } ++T[p = T[p].ch[d]].v; } ll s = 0; for (int i = 1; i <= n; ++i) { int p = b[i], d = w[i] >> o & 1; s += T[T[p].ch[d]].v; } int v = 0; if (k > s) k -= s, ans |= 1ll << o, v = 1; for (int i = 1; i <= n; ++i) { int &p = b[i], d = w[i] >> o & 1; p = T[p].ch[d ^ v]; } } cout << ans << endl; return0; }