#include <bits/stdc++.h>
using namespace std;
long long read() {
  char x = getchar();
  long long ans = 0;
  while (!isdigit(x)) x = getchar();
  while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
  return ans;
}
long long a[1000005], n, k;
struct graph {
  long long head[1000005], nxt[1000005], pnt[1000005], len[1000005], E;
  void add_edge(long long u, long long v, long long w) {
    pnt[E] = v;
    nxt[E] = head[u];
    len[E] = w;
    head[u] = E++;
  }
  void dfs(long long u, long long pre, long long sum) {
    a[u] = sum;
    for (long long i = head[u]; i != -1; i = nxt[i]) {
      long long v = pnt[i];
      if (v == pre) continue;
      dfs(v, u, sum ^ len[i]);
    }
  }
} G;
struct node {
  long long rt1, rt2, val;
};
long long son[1000005][2], siz[1000005], rt1[1000005], rt2[1000005],
    sum[1000005];
signed main() {
  memset(G.head, -1, sizeof(G.head));
  cin >> n >> k;
  for (long long i = 2; i <= n; i++) {
    long long u = read(), w = read();
    G.add_edge(u, i, w);
  }
  long long ANS = 0;
  G.dfs(1, 0, 0);
  for (long long i = 1; i <= n; i++) rt1[i] = rt2[i] = 0;
  for (long long i = 61; i >= 0; i--) {
    long long tot = 0;
    for (long long j = 0; j <= n; j++) son[j][0] = son[j][1] = sum[j] = 0;
    for (long long j = 1; j <= n; j++) {
      long long opt = (a[j] >> i) & 1;
      if (!son[rt1[j]][opt]) son[rt1[j]][opt] = ++tot;
      sum[son[rt1[j]][opt]]++;
      rt1[j] = son[rt1[j]][opt];
    }
    long long tmp = 0;
    for (long long j = 1; j <= n; j++) tmp += sum[son[rt2[j]][(a[j] >> i) & 1]];
    if (tmp < k) {
      ANS += (1ll << i);
      k -= tmp;
      for (long long j = 1; j <= n; j++)
        rt2[j] = son[rt2[j]][1 ^ ((a[j] >> i) & 1)];
    } else {
      for (long long j = 1; j <= n; j++) rt2[j] = son[rt2[j]][(a[j] >> i) & 1];
    }
  }
  cout << ANS;
}
