#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long matches(vector<long long> &a, vector<long long> &b, long long &m) {
  long long ans = 0;
  for (int i = 0, j = 0, k = 0; i < a.size(); i = j) {
    while (j < a.size() && (a[i] & m) == (a[j] & m)) j++;
    while (k < b.size() && (b[k] & m) <= (a[i] & m)) {
      if ((b[k] & m) == (a[i] & m)) ans += j - i;
      k++;
    }
  }
  return ans;
}
void flip(vector<long long> &a, long long b) {
  vector<long long> r1, r2;
  for (long long v : a) {
    if (v & b) {
      r1.push_back(v ^ b);
    } else {
      r2.push_back(v ^ b);
    }
  }
  merge((r1).begin(), (r1).end(), (r2).begin(), (r2).end(), a.begin());
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> vals(N);
  for (int i = 1; i < N; i++) {
    int dad;
    long long weight;
    cin >> dad >> weight;
    vals[i] = vals[dad - 1] ^ weight;
  }
  sort((vals).begin(), (vals).end());
  vector<long long> vxor = vals;
  vector<int> inx(N);
  long long res = 0, tot = 0, m = 0;
  for (int j = 61; j >= 0; j--) {
    long long b = 1ll << j;
    m += b;
    long long add = matches(vals, vxor, m);
    if (tot + add < K) {
      res ^= b;
      flip(vxor, b);
      tot += add;
    }
  }
  cout << res << endl;
  return 0;
}
