#include <bits/stdc++.h>
const int N = 1000005;
int nxt[N][2], size[N];
int n, pos[N], oppo[N], idx;
long long a[N], k, ans;
int allocate(int &x) { return x = x ?: ++idx; }
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> k;
  for (int i = 2, f; i <= n; ++i) std::cin >> f >> a[i], a[i] ^= a[f];
  for (int d = 61; ~d; --d) {
    for (int i = 0; i <= idx; ++i) nxt[i][0] = nxt[i][1] = size[i] = 0;
    long long s = 0;
    idx = 0;
    for (int i = 1; i <= n; ++i)
      ++size[pos[i] = allocate(nxt[pos[i]][a[i] >> d & 1])];
    for (int i = 1; i <= n; ++i) s += size[nxt[oppo[i]][a[i] >> d & 1]];
    for (int i = 1; i <= n; ++i)
      oppo[i] = nxt[oppo[i]][a[i] >> d & 1 ^ (k > s)];
    if (k > s) k -= s, ans |= 1LL << d;
  }
  std::cout << ans << '\n';
  return 0;
}
