#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
char buf[100000], *p1 = buf, *p2 = buf;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  }
  return (f == 1) ? x : -x;
}
const int maxn = 2e6 + 5;
int n, p[maxn], M = 62;
long long val[maxn], k;
int a[maxn], b[maxn], siz[maxn];
int son[maxn][2];
inline void init() {}
inline void input() {
  n = gi();
  scanf("%lld", &k);
  for (int i = 2; i <= n; ++i) {
    p[i] = gi();
    scanf("%lld", &val[i]);
    val[i] ^= val[p[i]];
  }
}
inline void solve() {
  long long ans = 0;
  for (int j = M; j >= 0; --j) {
    for (int i = 0; i <= n; ++i) son[i][0] = son[i][1] = siz[i] = 0;
    int cnt = 0;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
      int &p = son[a[i]][val[i] >> j & 1];
      if (!p) p = ++cnt;
      a[i] = p, siz[p]++;
    }
    for (int i = 1; i <= n; ++i) sum += siz[son[b[i]][val[i] >> j & 1]];
    bool op = 0;
    if (k > sum) k -= sum, ans |= 1LL << j, op = 1;
    for (int i = 1; i <= n; ++i) b[i] = son[b[i]][(val[i] >> j & 1) ^ op];
  }
  printf("%lld\n", ans);
}
int main() {
  init();
  input();
  solve();
  return 0;
}
