#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
long long read() {
  long long s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
long long K, Ans, dis[N];
int n, t, a[N], b[N], ch[2][N][2], sum[2][N], tot[2];
void Clear(int t) {
  for (int i = 0; i <= tot[t]; i++) sum[t][i] = ch[t][i][0] = ch[t][i][1] = 0;
  tot[t] = 0;
}
int main() {
  n = read();
  K = read();
  for (int i = 2; i <= n; i++) {
    int x = read();
    dis[i] = dis[x] ^ read();
  }
  for (int i = 1; i <= n; i++) a[i] = b[i] = 1;
  tot[t] = 1;
  for (int j = 62; j >= 0; j--) {
    long long Sum = 0, type = 0;
    Clear(t ^= 1);
    for (int i = 1; i <= n; i++) {
      int x = (dis[i] >> j) & 1;
      if (!ch[t ^ 1][a[i]][x]) ch[t ^ 1][a[i]][x] = ++tot[t];
      sum[t][ch[t ^ 1][a[i]][x]]++;
    }
    for (int i = 1; i <= n; i++)
      Sum += sum[t][ch[t ^ 1][b[i]][(dis[i] >> j) & 1]];
    if (K > Sum) {
      K -= Sum;
      Ans |= (1ll << j);
      type = 1;
    }
    for (int i = 1; i <= n; i++) {
      a[i] = ch[t ^ 1][a[i]][(dis[i] >> j) & 1];
      b[i] = ch[t ^ 1][b[i]][((dis[i] >> j) & 1) ^ type];
    }
  }
  printf("%lld\n", Ans);
  return 0;
}
