#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const long long MINF = 0x7f7f7f7f7f7f7f7fll;
const int N = 1e6 + 50;
long long val[N], fa[N];
int pp[N], ps[N];
int to[N][2], cnt[N * 2];
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = (2); i <= n; ++i)
    scanf("%lld%lld", &fa[i], &val[i]), val[i] ^= val[fa[i]];
  long long ans = 0;
  for (int j = (62); j >= 0; --j) {
    int tot = 0;
    long long num = 0;
    for (int i = (1); i <= n; ++i) {
      int d = (val[i] >> j) & 1;
      if (to[pp[i]][d] == 0) to[pp[i]][d] = ++tot;
      cnt[to[pp[i]][d]]++;
      pp[i] = to[pp[i]][d];
    }
    for (int i = (1); i <= n; ++i) {
      int d = (val[i] >> j) & 1;
      num += cnt[to[ps[i]][d]];
    }
    int flag = 0;
    if (num < k) k -= num, ans |= (1ll << j), flag = 1;
    for (int i = (1); i <= n; ++i) {
      int d = (val[i] >> j) & 1;
      ps[i] = to[ps[i]][d ^ flag];
    }
    memset(to, 0, sizeof to);
    memset(cnt, 0, sizeof cnt);
  }
  cout << ans << endl;
  return 0;
}
