#include <bits/stdc++.h>
using namespace std;
int N;
signed long long K;
signed long long V[1010101];
signed long long T[1010101];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  scanf("%d%" PRId64, &N, &K);
  for (i = 0; i < (N - 1); i++) {
    scanf("%d%" PRId64, &x, &V[i + 1]);
    V[i + 1] ^= V[x - 1];
  }
  sort(V, V + N);
  signed long long ret = 0;
  for (i = 61; i >= 0; i--) {
    for (j = 0; j < (N); j++) T[j] = (V[j] ^ ret) >> i;
    sort(T, T + N);
    int L = 0, R = 0;
    signed long long sum = 0;
    for (j = 0; j < (N); j++) {
      signed long long v = V[j] >> i;
      while (L < N && T[L] < v) L++;
      while (R < N && T[R] <= v) R++;
      sum += R - L;
    }
    if (sum < K) {
      K -= sum;
      ret ^= 1LL << i;
    }
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
