#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int L = 62;
int cnt, t, a[N], b[N], ch[N][2], sz[N];
long long k, s, ans, v[N];
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') f = -1, ch = getchar();
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline int add(int a, int b) { return ch[a][b] ? ch[a][b] : ch[a][b] = ++cnt; }
int main() {
  int n = read();
  long long k = read();
  for (int i = (int)(2); i <= (int)(n); ++i) {
    int p = read();
    v[i] = read();
    v[i] ^= v[p];
  }
  for (int i = (int)(1); i <= (int)(n); ++i) a[i] = b[i] = 1;
  for (int j = (int)(L); j >= (int)(0); --j) {
    for (int i = (int)(1); i <= (int)(cnt); ++i)
      ch[i][0] = ch[i][1] = sz[i] = 0;
    s = cnt = t = 0;
    for (int i = (int)(1); i <= (int)(n); ++i)
      sz[a[i] = add(a[i], v[i] >> j & 1)]++;
    for (int i = (int)(1); i <= (int)(n); ++i) s += sz[ch[b[i]][v[i] >> j & 1]];
    if (s < k) ans |= 1LL << j, k -= s, t = 1;
    for (int i = (int)(1); i <= (int)(n); ++i)
      b[i] = ch[b[i]][(v[i] >> j & 1) ^ t];
  }
  printf("%lld\n", ans);
  return 0;
}
