#include <bits/stdc++.h>
using namespace std;
const int M = 61;
int ch[2][1000010][2];
long long siz[2][1000010];
int cnt[2];
long long a[1000010];
int u[1000010];
int v[1000010];
int create(int x) {
  int y = ++cnt[x];
  ch[x][y][0] = 0;
  ch[x][y][1] = 0;
  siz[x][y] = 0;
  return y;
}
int main() {
  int n;
  long long k;
  scanf("%d %lld", &n, &k);
  a[1] = 0;
  for (int i = 2; i <= n; i++) {
    int p;
    long long w;
    scanf("%d %lld", &p, &w);
    a[i] = a[p] ^ w;
  }
  for (int i = 1; i <= n; i++) u[i] = v[i] = 1;
  long long ans = 0;
  for (int c = M; c >= 0; c--) {
    int now = c & 1;
    int lst = now ^ 1;
    cnt[now] = 0;
    for (int i = 1; i <= n; i++) {
      int x = (a[i] >> c) & 1;
      if (!ch[lst][u[i]][x]) ch[lst][u[i]][x] = create(now);
      u[i] = ch[lst][u[i]][x];
      siz[now][u[i]]++;
    }
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      int x = (a[i] >> c) & 1;
      sum += siz[now][ch[lst][v[i]][x]];
    }
    for (int i = 1; i <= n; i++) {
      int x = (a[i] >> c) & 1;
      if (k <= sum)
        v[i] = ch[lst][v[i]][x];
      else
        v[i] = ch[lst][v[i]][x ^ 1];
    }
    if (k > sum) {
      k -= sum;
      ans |= 1ll << c;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
