#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0LL) return b;
  if (b == 0LL) return a;
  return gcd(b, a % b);
}
const int N = 1000006;
long long first[N];
int trie[2][N], cnt[N];
int cur1[N], cur2[N];
inline bool isSet(int i, int j) { return (first[i] & (1LL << j)); }
void solve() {
  int n, p;
  long long k, w;
  cin >> n >> k;
  cur1[0] = cur2[0] = 0;
  for (int i = 1; i < n; i++) {
    cin >> p >> w;
    first[i] = first[p - 1] ^ w;
    cur1[i] = cur2[i] = 0;
  }
  long long ans = 0LL, temp;
  int node_cnt, edge;
  bool flag;
  for (int j = 61; j >= 0; j--) {
    node_cnt = 1;
    memset(cnt, 0, sizeof(cnt));
    memset(trie, 0, sizeof(trie));
    for (int i = 0; i < n; i++) {
      edge = isSet(i, j);
      if (trie[edge][cur1[i]] == 0) trie[edge][cur1[i]] = node_cnt++;
      cur1[i] = trie[edge][cur1[i]];
      cnt[cur1[i]]++;
    }
    temp = 0LL;
    for (int i = 0; i < n; i++) {
      edge = isSet(i, j);
      temp += cnt[trie[edge][cur2[i]]];
    }
    flag = false;
    if (temp < k) {
      flag = true;
      k -= temp;
      ans += (1LL << j);
    }
    for (int i = 0; i < n; i++) {
      edge = isSet(i, j) ^ flag;
      cur2[i] = trie[edge][cur2[i]];
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  clock_t clk = clock();
  int t = 1;
  for (int tests = 1; tests <= t; tests++) {
    solve();
  }
  clk = clock() - clk;
  cerr << "Time Elapsed: " << fixed << setprecision(10)
       << ((long double)clk) / CLOCKS_PER_SEC << "\n";
  return 0;
}
