#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
inline long long readint() {
  long long res = 0, f = 1;
  char c = 0;
  while (!isdigit(c)) {
    c = getchar();
    if (c == '-') f = -1;
  }
  while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res * f;
}
int n;
long long k;
struct Node {
  int u, v;
  long long c;
  Node *next;
} * h[MAXN], pool[MAXN << 1];
int tot = 0;
inline void addEdge(int u, int v, long long c) {
  Node *p = &pool[++tot], *q = &pool[++tot];
  p->v = v;
  p->c = c;
  p->next = h[u];
  h[u] = p;
  q->v = u;
  q->c = c;
  q->next = h[v];
  h[v] = q;
}
long long s[MAXN];
inline void dfs(int u, int fa) {
  for (Node *p = h[u]; p; p = p->next)
    if (p->v != fa) s[p->v] = s[u] ^ p->c, dfs(p->v, u);
}
int ch[2][MAXN][2], size[2][MAXN];
int cnt[2], pos[MAXN], pos2[MAXN];
int main() {
  n = readint(), k = readint();
  for (int i = 2; i <= n; i++) {
    int x;
    long long c;
    x = readint(), c = readint();
    addEdge(x, i, c);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) pos[i] = pos2[i] = 1;
  long long ans = 0;
  for (int i = 62; i >= 0; i--) {
    int t = i & 1, u = i & 1 ^ 1;
    cnt[t] = 0;
    for (int j = 1; j <= n; j++) {
      int p = (s[j] >> i) & 1;
      size[u][pos[j]] = 0;
      if (!ch[u][pos[j]][p]) ch[u][pos[j]][p] = ++cnt[t];
      pos[j] = ch[u][pos[j]][p], size[t][pos[j]]++;
      ch[t][pos[j]][0] = ch[t][pos[j]][1] = 0;
    }
    long long sum = 0;
    for (int j = 1; j <= n; j++) {
      int p = (s[j] >> i) & 1;
      sum += size[t][ch[u][pos2[j]][p]];
    }
    for (int j = 1; j <= n; j++) {
      int p = (s[j] >> i) & 1;
      if (k > sum)
        pos2[j] = ch[u][pos2[j]][p ^ 1];
      else
        pos2[j] = ch[u][pos2[j]][p];
    }
    if (k > sum) k -= sum, ans |= 1ll << i;
  }
  cout << ans << endl;
  return 0;
}
