#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n;
long long k;
long long d[N];
int v1[N], v2[N];
int go[N][3];
long long t[N];
int main() {
  cin >> n >> k;
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d%lld", &p, &d[i]);
    d[i] ^= d[p];
  }
  for (int i = 1; i <= n; i++) {
    v1[i] = v2[i] = 1;
  }
  long long answ = 0;
  for (int i = 61; i >= 0; i--) {
    int timer = 1;
    for (int j = 1; j <= n; j++) {
      t[j] = 0;
      go[j][0] = go[j][1] = 0;
    }
    for (int j = 1; j <= n; j++) {
      int bit = ((d[j] >> i) & 1);
      if (go[v1[j]][bit] == 0) {
        go[v1[j]][bit] = ++timer;
      }
      t[go[v1[j]][bit]]++;
      v1[j] = go[v1[j]][bit];
    }
    long long s0 = 0;
    for (int j = 1; j <= n; j++) {
      int bit = ((d[j] >> i) & 1);
      s0 += t[go[v2[j]][bit]];
    }
    int flag = 0;
    if (s0 < k) {
      k -= s0;
      answ += (1ll << i);
      flag = 1;
    }
    for (int j = 1; j <= n; j++) {
      int bit = ((d[j] >> i) & 1);
      v2[j] = go[v2[j]][bit ^ flag];
    }
  }
  cout << answ << endl;
  return 0;
}
