#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
int const N = 1e6 + 20, LG = 62;
int n;
ll k;
ll d[N];
vector<pair<int, ll>> child[N];
int cur1[N], cur2[N];
int trie[N * 5][2], cnt[N * 5], sz = 1;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1, p; i < n; i++) {
    ll x;
    cin >> p >> x;
    p--;
    child[p].push_back({i, x});
    d[i] = d[p] ^ x;
  }
  ll ans = 0;
  trie[0][0] = trie[0][1] = -1;
  cnt[0] = 0;
  sz = 1;
  for (int i = 0; i < n; i++) cur1[i] = cur2[i] = 0;
  ll sum = 0;
  for (int j = LG - 1; j >= 0; j--) {
    ll val = 0;
    for (int i = 0; i < n; i++) {
      ll x = d[i];
      bool b = ((x & (1ll << j)) > 0);
      if (trie[cur1[i]][b] == -1) {
        trie[cur1[i]][b] = sz;
        trie[sz][0] = trie[sz][1] = -1;
        cnt[sz] = 0;
        sz++;
        if (sz == 5 * N) sz = 0;
      }
      cur1[i] = trie[cur1[i]][b];
      cnt[cur1[i]]++;
    }
    for (int i = 0; i < n; i++) {
      ll x = d[i];
      if (cur2[i] == -1) continue;
      bool b = ((x & (1ll << j)) > 0);
      int nxt = trie[cur2[i]][b ^ 1];
      if (nxt != -1) val += cnt[nxt];
    }
    bool fl = 0;
    if (sum + val > 1ll * n * n - k)
      fl = 1, ans |= (1ll << j);
    else
      sum += val;
    for (int i = 0; i < n; i++) {
      if (cur2[i] == -1) continue;
      bool b = ((d[i] & (1ll << j)) > 0);
      cur2[i] = trie[cur2[i]][b ^ fl];
    }
  }
  cout << ans << '\n';
}
