#include <bits/stdc++.h>
long long s, ans, K, y, D[1000005];
int ch, o, x, a, i, j, sz, p, d[1000005], e[1000005], data[2][1000005][3];
int main() {
  scanf("%d%lld", &a, &K);
  for (i = 2; i <= a; i++) {
    scanf("%d%lld", &x, &y);
    D[i] = D[x] ^ y;
  }
  sz = 1;
  for (i = 1; i <= a; i++) d[i] = e[i] = 1;
  for (j = 61; j >= 0; j--) {
    s = 0;
    sz = 0;
    for (i = 1; i <= a; i++) {
      p = D[i] & (1ll << j) ? 2 : 1;
      if (data[o][d[i]][p] == 0) data[o][d[i]][p] = ++sz;
      d[i] = data[o][d[i]][p];
      data[1 - o][d[i]][0]++;
    }
    for (i = 1; i <= a; i++) {
      p = D[i] & (1ll << j) ? 2 : 1;
      s += data[1 - o][data[o][e[i]][p]][0];
    }
    if (s < K) {
      K -= s;
      ans |= (1ll << j);
      ch = 1;
    } else
      ch = 0;
    for (i = 1; i <= a; i++) {
      p = ((D[i] & (1ll << j)) ? 1 : 0) == ch ? 1 : 2;
      e[i] = data[o][e[i]][p];
    }
    o = 1 - o;
    for (i = 1; i <= a; i++) data[o][i][0] = data[o][i][1] = data[o][i][2] = 0;
  }
  printf("%lld", ans);
}
