#include <bits/stdc++.h>
const int N = 1000010;
int n, tot = 1, trin[N], trqy[N], tr[N][2], siz[N];
long long k, a[N];
int main() {
  scanf("%d%lld", &n, &k);
  trin[1] = trqy[1] = 1;
  int u;
  for (int i = 2; i <= n; ++i) {
    scanf("%d%lld", &u, &a[i]);
    a[i] ^= a[u];
    trin[i] = trqy[i] = 1;
  }
  long long ans = 0;
  for (int i = 62; ~i; --i) {
    long long cnt = 0;
    int tot = 0;
    bool nxt = 0;
    for (int j = 1; j <= n; ++j) {
      tr[j][0] = tr[j][1] = siz[j] = 0;
    }
    for (int j = 1; j <= n; ++j) {
      bool tmp = (a[j] >> i) & 1;
      if (!tr[trin[j]][tmp]) {
        tr[trin[j]][tmp] = ++tot;
      }
      trin[j] = tr[trin[j]][tmp];
      ++siz[trin[j]];
    }
    for (int j = 1; j <= n; ++j) {
      cnt += 0ll + siz[tr[trqy[j]][(a[j] >> i) & 1]];
    }
    if (cnt < k) {
      ans |= 1ll << i;
      nxt = true;
      k -= cnt;
    }
    for (int j = 1; j <= n; ++j) {
      trqy[j] = tr[trqy[j]][nxt ^ ((a[j] >> i) & 1)];
    }
  }
  printf("%lld", ans);
  return 0;
}
