#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int n, cnt, son[N][2], pre[N], now[N], sz[N], f;
long long ans, sum, k, w[N];
void init() {
  for (int i = 1; i <= cnt; i++) son[i][0] = son[i][1] = sz[i] = 0;
  cnt = sum = f = 0;
}
int fun(int x, int y) {
  if (!son[x][y]) son[x][y] = ++cnt;
  return son[x][y];
}
int main() {
  scanf("%d%lld", &n, &k);
  pre[1] = now[1] = 1;
  for (int i = 2, fa; i <= n; i++)
    scanf("%d%lld", &fa, &w[i]), w[i] ^= w[fa], pre[i] = now[i] = 1;
  for (int i = 61; ~i; i--) {
    init();
    for (int j = 1; j <= n; j++)
      now[j] = fun(now[j], w[j] >> i & 1), sz[now[j]]++;
    for (int j = 1; j <= n; j++) sum += sz[son[pre[j]][w[j] >> i & 1]];
    if (sum < k) k -= sum, ans += 1LL << i, f = 1;
    for (int j = 1; j <= n; j++) pre[j] = son[pre[j]][(w[j] >> i & 1) ^ f];
  }
  printf("%lld\n", ans);
  return 0;
}
