#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Read(T &n) {
  char c;
  n = 0;
  while (!isdigit(c = getchar()))
    ;
  do {
    n = n * 10 + c - '0';
  } while (isdigit(c = getchar()));
}
const int N = 1E6 + 2;
const int B = 62;
int n;
long long k, a[N];
int ver1[N], ver2[N];
int Tsize, cnt[N], child[N][2];
void Read_Input() {
  Read(n);
  Read(k);
  for (int i = 2; i <= n; i++) {
    int u;
    long long w;
    Read(u);
    Read(w);
    a[i] = a[u] ^ w;
  }
}
long long Cal(int pos) {
  Tsize = 0;
  memset(cnt, 0, sizeof(cnt));
  memset(child, -1, sizeof(child));
  for (int i = 1; i <= n; i++) {
    int c = a[i] >> pos & 1;
    if (ver1[i] == -1) continue;
    if (child[ver1[i]][c] == -1) child[ver1[i]][c] = ++Tsize;
    ver1[i] = child[ver1[i]][c];
    cnt[ver1[i]]++;
  }
  long long ret = 0;
  for (int i = 1; i <= n; i++) {
    int c = a[i] >> pos & 1;
    if (ver2[i] == -1) continue;
    ret += cnt[child[ver2[i]][c]];
  }
  return ret;
}
void Solve() {
  long long ans = 0;
  for (int pos = 61; pos >= 0; pos--) {
    long long x = Cal(pos);
    if (x < k) {
      k -= x;
      ans |= 1ll << pos;
      for (int i = 1; i <= n; i++) {
        int c = a[i] >> pos & 1;
        if (ver2[i] == -1) continue;
        ver2[i] = child[ver2[i]][c ^ 1];
      }
    } else {
      for (int i = 1; i <= n; i++) {
        int c = a[i] >> pos & 1;
        if (ver2[i] == -1) continue;
        ver2[i] = child[ver2[i]][c];
      }
    }
  }
  printf("%I64d", ans);
}
int main() {
  Read_Input();
  Solve();
  return 0;
}
