#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 50;
int n;
long long k;
long long a[N], f[N], tmp[N];
long long res, all;
void change(int i) {
  int l = 0, r = 0;
  long long rest = all ^ (1LL << i);
  for (int j = 0; j < n; j = r) {
    r = l = j;
    while (l < n && (f[j] & all) == (f[l] & all)) l++;
    while (r < n && (f[j] & rest) == (f[r] & rest)) r++;
    int ci = j;
    for (int k = l; k < r; k++) tmp[ci++] = f[k];
    for (int k = j; k < l; k++) tmp[ci++] = f[k];
    for (int k = j; k < r; k++) f[k] = tmp[k];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    p--;
    long long x;
    cin >> x;
    a[i] = a[p] ^ x;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) f[i] = a[i];
  for (int b = 61; b >= 0; b--) {
    int l = 0, r = 0;
    all |= (1LL << b);
    long long s = 0;
    for (int i = 0; i < n; i++) {
      long long cur = (f[i] ^ res) & all;
      while (l < n && (a[l] & all) < cur) l++;
      while (r < n && (a[r] & all) <= cur) r++;
      s += r - l;
    }
    if (s < k) {
      k -= s;
      change(b);
      res |= (1LL << b);
    }
  }
  cout << res << endl;
}
