#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
struct Trie {
  int ch[2];
} Tr[maxn];
int now;
int sum[maxn], pos[maxn], fr[maxn], sfr[maxn];
int n, root;
long long Rk;
long long A[maxn], dis[maxn];
int tot;
int h[maxn], last[maxn], to[maxn];
long long w[maxn];
void add(int x, int y, long long z) {
  to[++tot] = y, last[tot] = h[x], h[x] = tot, w[tot] = z;
}
void dfs(int x, int fa) {
  for (int i = h[x]; i; i = last[i]) {
    int v = to[i];
    if (v == fa) continue;
    dis[v] = dis[x] ^ w[i];
    dfs(v, x);
  }
}
long long bfs(int d) {
  if (d < 0) return 0;
  int snow = 0;
  long long scnt = 0;
  for (int i = 1; i <= now; ++i)
    Tr[i].ch[0] = Tr[i].ch[1] = sum[i] = 0, sfr[i] = fr[i];
  for (int i = 1; i <= n; ++i) {
    int s = (dis[i] >> d) & 1;
    if (!Tr[pos[i]].ch[s]) Tr[pos[i]].ch[s] = ++snow;
    ++sum[Tr[pos[i]].ch[s]];
    pos[i] = Tr[pos[i]].ch[s];
  }
  for (int i = 1; i <= now; ++i) {
    int s = fr[i];
    scnt += (long long)sum[Tr[i].ch[0]] * sum[Tr[s].ch[0]] +
            (long long)sum[Tr[i].ch[1]] * sum[Tr[s].ch[1]];
  }
  long long s = 0;
  if (scnt < Rk) {
    Rk -= scnt;
    s |= (1LL << d);
    for (int i = 1; i <= now; ++i)
      for (int j = 0; j <= 1; ++j) fr[Tr[i].ch[j]] = Tr[sfr[i]].ch[j ^ 1];
  } else {
    for (int i = 1; i <= now; ++i)
      for (int j = 0; j <= 1; ++j) fr[Tr[i].ch[j]] = Tr[sfr[i]].ch[j];
  }
  now = snow;
  return s | bfs(d - 1);
}
int main() {
  scanf("%d%lld", &n, &Rk);
  for (int i = 2; i <= n; ++i) {
    int a = 0;
    long long b = 0;
    scanf("%d%lld", &a, &b);
    add(a, i, b);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) pos[i] = 1;
  fr[1] = 1, now = 1;
  printf("%lld", bfs(61));
  return 0;
}
