#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 70;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
int n, m;
long long k;
long long a[maxn];
int cl[maxn], cr[maxn], nxt[maxn];
long long tmp[maxn];
long long solve() {
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cl[i] = 0;
    cr[i] = n;
  }
  long long ans = 0, t = k;
  for (int c = 61; c >= 0; c--) {
    nxt[n] = n;
    for (int i = n - 1; i >= 0; i--)
      nxt[i] = ((a[i] >> c) & 1 ? i : nxt[i + 1]);
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      int mid = min(cr[i], nxt[cl[i]]);
      cnt += ((a[i] >> c) & 1 ? cr[i] - mid : mid - cl[i]);
    }
    if (cnt < t) {
      t -= cnt;
      ans += (1ll << c);
      for (int i = 0; i < n; i++) {
        int mid = min(cr[i], nxt[cl[i]]);
        (a[i] >> c) & 1 ? cr[i] = mid : cl[i] = mid;
      }
    } else {
      for (int i = 0; i < n; i++) {
        int mid = min(cr[i], nxt[cl[i]]);
        (a[i] >> c) & 1 ? cl[i] = mid : cr[i] = mid;
      }
    }
  }
  return ans;
}
long long solve2() {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      tmp[cnt++] = a[i] ^ a[j];
    }
  }
  sort(tmp, tmp + cnt);
  return tmp[k - 1];
}
void check(int n, int m) {
  bool flag = 1;
  while (m--) {
    k = rand() % (n * n) + 1;
    for (int i = 0; i < n; i++) a[i] = rand();
    long long ans = solve();
    long long ans2 = solve2();
    if (ans != ans2) {
      cout << "n: " << n << " ,k: " << k << endl;
      cout << "a: ";
      for (int i = 0; i < n; i++) cout << a[i] << " ";
      cout << endl;
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          tmp[cnt++] = a[i] ^ a[j];
        }
      }
      sort(tmp, tmp + cnt);
      cout << "tmp: ";
      for (int i = 0; i < cnt; i++) cout << tmp[i] << " ";
      cout << endl;
      cout << "ans: " << ans << " ,ans2: " << ans2 << endl;
      flag = 0;
      break;
    }
  }
  if (flag) cout << "YES" << endl;
}
int main() {
  srand(time(NULL));
  while (cin >> n >> k) {
    a[0] = 0;
    for (int i = 1; i < n; i++) {
      int p;
      long long x;
      scanf("%d%lld", &p, &x);
      p--;
      a[i] = a[p] ^ x;
    }
    sort(a, a + n);
    long long ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}
