#include <bits/stdc++.h>
using namespace std;
int cnt[1000009], trie[1000009][2], cur1[1000009], cur2[1000009];
long long int a[1000009];
int main() {
  int i, j, t1, t2, t3, t4, n, cur, prefone;
  long long int buf1, buf2, buf3, buf4, k, ans, tempcnt;
  scanf("%d %lld", &n, &k);
  a[1] = 0;
  for (i = 2; i <= n; i++) {
    scanf("%d %lld", &t1, &buf1);
    a[i] = a[t1] ^ buf1;
  }
  ans = 0;
  memset(cur1, 0, sizeof(cur1));
  memset(cur2, 0, sizeof(cur2));
  for (j = 61; j >= 0; j--) {
    memset(trie, -1, sizeof(trie));
    memset(cnt, 0, sizeof(cnt));
    cur = 1;
    for (i = 1; i <= n; i++) {
      t1 = ((1ll << j) & a[i]) ? 1 : 0;
      if (trie[cur1[i]][t1] == -1) {
        trie[cur1[i]][t1] = cur++;
      }
      cur1[i] = trie[cur1[i]][t1];
      cnt[cur1[i]]++;
    }
    tempcnt = 0;
    for (i = 1; i <= n; i++) {
      t1 = ((1ll << j) & a[i]) ? 1 : 0;
      tempcnt += cnt[trie[cur2[i]][t1]];
    }
    prefone = 0;
    if (tempcnt >= k) {
    } else {
      k -= tempcnt;
      ans |= (1ll << j);
      prefone = 1;
    }
    for (i = 1; i <= n; i++) {
      t1 = ((1ll << j) & a[i]) ? 1 : 0;
      t1 ^= prefone;
      cur2[i] = trie[cur2[i]][t1];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
