#include <bits/stdc++.h>
using namespace std;
long long a, b, q, w, d[1000001], fa[1000001], now[1000001], si[1000001],
    cnt = 1, l[1000001][2], ans;
long long get(long long qq, long long ww) {
  if (!l[qq][ww]) {
    l[qq][ww] = ++cnt;
  }
  return l[qq][ww];
}
int main() {
  scanf("%lld%lld", &a, &b);
  now[1] = fa[1] = 1;
  for (int i = 2; i <= a; i++) {
    now[i] = fa[i] = 1;
    scanf("%lld%lld", &q, &w);
    d[i] = d[q] ^ w;
  }
  for (int i = 61; i >= 0; i--) {
    long long hh = 0;
    cnt = 0;
    for (int j = 1; j <= a; j++) {
      l[j][0] = l[j][1] = si[j] = 0;
    }
    for (int j = 1; j <= a; j++) {
      now[j] = get(now[j], (d[j] >> (long long)(i)) & 1);
      si[now[j]]++;
    }
    for (int j = 1; j <= a; j++) {
      hh += si[l[fa[j]][(d[j] >> (long long)(i)) & 1]];
    }
    long long opp = 0;
    if (hh < b) {
      opp = 1;
      b -= hh;
      ans |= ((long long)(1) << (long long)(i));
    }
    for (int j = 1; j <= a; j++) {
      fa[j] = l[fa[j]][((d[j] >> (long long)(i)) & 1) ^ opp];
    }
  }
  printf("%lld", ans);
  return 0;
}
