#include <bits/stdc++.h>
using i64 = long long;
const int N = 1000007;
int tot, p[N], q[N];
i64 a[N];
struct node {
  int size, ch[2];
} t[N];
char ibuf[1 << 25 | 1], *iS = ibuf;
i64 read() {
  i64 x = 0;
  while (isspace(*iS)) ++iS;
  while (isdigit(*iS)) (x *= 10) += *iS++ & 15;
  return x;
}
int get(int p, int d) { return t[p].ch[d] ? t[p].ch[d] : t[p].ch[d] = ++tot; }
int main() {
  fread(ibuf, 1, 1 << 25, stdin);
  int n = read();
  i64 k = read(), ans = 0;
  for (int i = 2, fa; i <= n; ++i) fa = read(), a[i] = a[fa] ^ read();
  for (int i = 1; i <= n; ++i) p[i] = q[i] = 1;
  for (int d = 61; ~d; --d) {
    memset(t + 1, 0, 12 * tot);
    i64 s = tot = 0;
    for (int i = 1; i <= n; ++i) ++t[p[i] = get(p[i], a[i] >> d & 1)].size;
    for (int i = 1; i <= n; ++i) s += t[t[q[i]].ch[a[i] >> d & 1]].size;
    for (int i = 1; i <= n; ++i) q[i] = t[q[i]].ch[(a[i] >> d & 1) ^ (k > s)];
    if (k > s) k -= s, ans |= 1ll << d;
  }
  printf("%lld", ans);
}
