#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
const int N = 2e6 + 7;
int n, edc;
int ch[N][2], cnt[N], lst[N];
int t[2] = {0, 1000000};
long long upv[N];
long long K, ans;
struct data {
  int a, b, opt;
} f[N >> 1], g[N >> 1];
void get(int dep, int tot, long long K) {
  if (dep < 0) return;
  int ndc = 0;
  for (int i = 1; i <= n; ++i)
    ch[i + t[dep & 1]][0] = ch[i + t[dep & 1]][1] = cnt[i + t[dep & 1]] = 0;
  for (int i = 1; i <= n; ++i) {
    int c = upv[i] >> dep & 1;
    if (!ch[lst[i]][c]) ch[lst[i]][c] = (++ndc) + t[dep & 1];
    lst[i] = ch[lst[i]][c];
    ++cnt[lst[i]];
  }
  int gg1 = 0, gg2 = 0;
  long long c[2];
  c[0] = c[1] = 0;
  for (int i = 1; i <= tot; ++i) {
    for (int j = 0; j <= 1; ++j)
      for (int k = 0; k <= 1; ++k)
        if (ch[f[i].a][j] && ch[f[i].b][k]) {
          c[j ^ k] += 1ll * cnt[ch[f[i].a][j]] * cnt[ch[f[i].b][k]];
          g[++gg1] = (data){ch[f[i].a][j], ch[f[i].b][k], j ^ k};
        }
  }
  int cho = 0;
  if (c[0] < K) cho = 1, K -= c[0];
  ans |= 1ll * cho << dep;
  for (int i = 1; i <= gg1; ++i)
    if (g[i].opt == cho) f[++gg2] = g[i];
  get(dep - 1, gg2, K);
}
int main() {
  scanf("%d%lld", &n, &K);
  for (int i = 2; i <= n; ++i) {
    int fa;
    long long v;
    scanf("%d%lld", &fa, &v);
    upv[i] = upv[fa] ^ v;
  }
  get(62, 1, K);
  printf("%lld\n", ans);
  return 0;
}
