#include <bits/stdc++.h>
using namespace std;
long long int x[1000000];
struct inter {
  int l1, r1, l2, r2;
};
vector<inter> vv, vv2;
int main() {
  int i;
  int n, p;
  long long int kk, w;
  scanf("%d %I64d", &n, &kk);
  for (i = 1; i < n; i++) scanf("%d %I64d", &p, &w), x[i] = x[p - 1] ^ w;
  sort(x, x + n);
  int j;
  long long int ans = 0;
  for (i = 61; i >= 0; i--) {
    long long int c = 0, cc = 0;
    for (j = 0; j < n; j++) {
      if (j == 0)
        cc = 1;
      else {
        if ((x[j - 1] >> i) == (x[j] >> i))
          cc++;
        else
          c += cc * cc, cc = 1;
      }
    }
    c += cc * cc;
    if (c < kk) {
      kk -= c, ans |= (1LL << i);
      break;
    }
  }
  if (i == -1) {
    printf("0\n");
    return 0;
  }
  int b = i;
  vector<pair<int, int> > v;
  for (i = 0; i < n; i++) {
    long long int m = x[i] >> b;
    if (v.empty())
      v.push_back(make_pair(i, i));
    else {
      if ((x[i - 1] >> b) == m)
        v.back().second++;
      else
        v.push_back(make_pair(i, i));
    }
  }
  for (i = 1; i < v.size(); i++) {
    if ((x[v[i - 1].first] >> b) == ((x[v[i].first] >> b) ^ 1))
      vv.push_back(
          (inter){v[i - 1].first, v[i - 1].second, v[i].first, v[i].second});
  }
  int k;
  for (i = b - 1; i >= 0; i--) {
    long long int c = 0;
    for (j = 0; j < vv.size(); j++) {
      int a = 0, b = 0, a2 = 0, b2 = 0;
      for (k = vv[j].l1; k <= vv[j].r1; k++) {
        if ((x[k] >> i) & 1)
          b++;
        else
          a++;
      }
      for (k = vv[j].l2; k <= vv[j].r2; k++) {
        if ((x[k] >> i) & 1)
          b2++;
        else
          a2++;
      }
      c += (long long int)a * a2 + (long long int)b * b2;
    }
    c *= 2;
    for (j = 0; j < vv.size(); j++) {
      for (k = vv[j].l1; k <= vv[j].r1; k++) {
        if ((x[k] >> i) & 1) break;
      }
      int p = k;
      for (k = vv[j].l2; k <= vv[j].r2; k++) {
        if ((x[k] >> i) & 1) break;
      }
      if (c < kk) {
        vv2.push_back((inter){vv[j].l1, p - 1, k, vv[j].r2});
        vv2.push_back((inter){p, vv[j].r1, vv[j].l2, k - 1});
      } else {
        vv2.push_back((inter){vv[j].l1, p - 1, vv[j].l2, k - 1});
        vv2.push_back((inter){p, vv[j].r1, k, vv[j].r2});
      }
    }
    vv.clear();
    for (j = 0; j < vv2.size(); j++) {
      if ((vv2[j].r1 >= vv2[j].l1) && (vv2[j].r2 >= vv2[j].l2))
        vv.push_back(vv2[j]);
    }
    vv2.clear();
    if (c < kk) kk -= c, ans |= (1LL << i);
  }
  printf("%I64d\n", ans);
  return 0;
}
