#include <bits/stdc++.h>
using namespace std;
const int N = 2000050;
int n, cc, t, a[N], b[N], ch[N][2], sz[N];
long long k, s, ans, v[N];
int gt(int a, int b) { return ch[a][b] ? ch[a][b] : ch[a][b] = ++cc; }
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 2, p; i <= n; i++) scanf("%d%lld", &p, &v[i]), v[i] ^= v[p];
  for (int i = 1; i <= n; i++) a[i] = b[i] = 1;
  for (int j = 61; ~j; j--) {
    for (int i = 1; i <= cc; i++) ch[i][0] = ch[i][1] = sz[i] = 0;
    s = cc = t = 0;
    for (int i = 1; i <= n; i++) sz[a[i] = gt(a[i], v[i] >> j & 1)]++;
    for (int i = 1; i <= n; i++) s += sz[ch[b[i]][v[i] >> j & 1]];
    if (s < k) ans |= 1ll << j, k -= s, t = 1;
    for (int i = 1; i <= n; i++) b[i] = ch[b[i]][(v[i] >> j & 1) ^ t];
  }
  printf("%lld\n", ans);
  return 0;
}
