#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a * fh;
}
long long n, k, val[1000005], loc[1000005], fk[1000005];
long long to[1000005 << 2][2], siz[1000005 << 2], cnt = 1;
long long st[1000005 << 2], top;
long long p[1000005 << 2];
bool in[1000005 << 2];
long long newnode() {
  long long first;
  if (top) {
    in[st[top]] = 0;
    first = st[top--];
  } else
    first = ++cnt;
  if (!first || first == 1) {
    cout << "FKFKF" << endl;
    exit(0);
  }
  to[first][0] = to[first][1] = 0;
  siz[first] = 0;
  return first;
}
long long node(long long &first) {
  if (!first) first = newnode();
  return first;
}
signed main() {
  n = read();
  k = read();
  for (long long i = 1; i <= n; ++i) loc[i] = fk[i] = 1;
  for (long long i = 2; i <= n; ++i) {
    long long fa = read();
    val[i] = read() ^ val[fa];
  }
  long long ans = 0;
  for (long long i = 61; i >= 0; --i) {
    long long N = 0;
    for (long long j = 1; j <= n; ++j) {
      if (!in[loc[j]] && loc[j] > 1) p[++N] = loc[j], in[loc[j]] = 1;
      loc[j] = node(to[loc[j]][(val[j] >> i) & 1]);
      siz[loc[j]]++;
    }
    long long tot = 0;
    for (long long j = 1; j <= n; ++j) {
      tot += siz[to[fk[j]][(val[j] >> i) & 1]];
    }
    if (tot < k) {
      k -= tot, ans |= (1ll << i);
      for (long long j = 1; j <= n; ++j) {
        fk[j] = to[fk[j]][!((val[j] >> i) & 1)];
      }
    } else {
      if (!i) {
        if (tot < k) {
          cout << "tot<k" << endl;
          exit(0);
        }
      }
      for (long long j = 1; j <= n; ++j) {
        fk[j] = to[fk[j]][(val[j] >> i) & 1];
      }
    }
    for (long long j = 1; j <= N; ++j) st[++top] = p[j];
  }
  printf("%lld\n", ans);
  return 0;
}
