#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> w(n);
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p >> w[i];
    w[i] ^= w[p - 1];
  }
  ll sol = 0;
  sort(begin(w), end(w));
  vector<array<int, 4>> list = {{0, n, 0, n}};
  for (int b = 61; b >= 0; --b) {
    auto binsearch = [&](int lo, int hi) {
      while (lo < hi) {
        int md = (lo + hi) / 2;
        if (w[md] >> b & 1) {
          hi = md;
        } else {
          lo = md + 1;
        }
      }
      return lo;
    };
    ll cnt0 = 0;
    for (auto [l1, r1, l2, r2] : list) {
      int m1 = binsearch(l1, r1);
      int m2 = binsearch(l2, r2);
      cnt0 += 1LL * (m1 - l1) * (m2 - l2);
      cnt0 += 1LL * (r1 - m1) * (r2 - m2);
    }
    if (cnt0 < k) {
      sol |= 1LL << b;
      k -= cnt0;
    }
    vector<array<int, 4>> tmp;
    for (auto [l1, r1, l2, r2] : list) {
      int m1 = binsearch(l1, r1);
      int m2 = binsearch(l2, r2);
      if (sol >> b & 1) {
        if (l1 < m1 && m2 < r2) tmp.push_back({l1, m1, m2, r2});
        if (m1 < r1 && l2 < m2) tmp.push_back({m1, r1, l2, m2});
      } else {
        if (l1 < m1 && l2 < m2) tmp.push_back({l1, m1, l2, m2});
        if (m1 < r1 && m2 < r2) tmp.push_back({m1, r1, m2, r2});
      }
    }
    swap(list, tmp);
  }
  cout << sol << '\n';
}
