#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c h, c n) {
  return {h, n};
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
  template <class c>
  muu &operator<<(const c &) {
    return *this;
  }
};
const int N = 1e6 + 7;
int n;
long long k;
vector<pair<int, long long>> G[N];
long long h[N];
const int M = 62;
void dfs(int v) {
  for (auto u : G[v]) {
    h[u.first] = h[v] ^ u.second;
    dfs(u.first);
  }
}
struct node {
  int ap, ak, bp, bk;
  node(int _ap, int _ak, int _bp, int _bk)
      : ap(_ap), ak(_ak), bp(_bp), bk(_bk) {}
  node() {}
};
int vA[2][N];
int vB[2][N];
node poz[2][N];
int ilePoz[2];
int main() {
  scanf("%d %lld", &n, &k);
  for (int i = 2; i <= n; ++i) {
    int p;
    long long w;
    scanf("%d %lld", &p, &w);
    G[p].push_back({i, w});
  }
  dfs(1);
  long long wyn = 0;
  poz[M % 2][0] = node(1, n, 1, n);
  ilePoz[M % 2] = 1;
  for (int i = 1; i <= n; ++i) vA[M % 2][i] = vB[M % 2][i] = i;
  for (int i = M - 1; i >= 0; --i) {
    int *nA = vA[i % 2];
    int *nB = vB[i % 2];
    int *sA = vA[(i + 1) % 2];
    int *sB = vB[(i + 1) % 2];
    node *sPoz = poz[(i + 1) % 2];
    node *nPoz = poz[i % 2];
    int &ileP = ilePoz[(i + 1) % 2];
    int &nileP = ilePoz[i % 2];
    long long ile = 0;
    long long mm = (1LL << i);
    for (int it = 0; it < ileP; ++it) {
      const node &u = sPoz[it];
      int ilea0 = 0;
      int ilea1 = 0;
      int ileb0 = 0;
      int ileb1 = 0;
      for (int j = u.ap; j <= u.ak; ++j) {
        int v = sA[j];
        if (h[v] & mm)
          ilea1++;
        else
          ilea0++;
      }
      for (int j = u.bp; j <= u.bk; ++j) {
        int v = sB[j];
        if (h[v] & mm)
          ileb1++;
        else
          ileb0++;
      }
      ile += 1ll * ilea0 * ileb0;
      ile += 1ll * ilea1 * ileb1;
    }
    bool flip = 0;
    if (ile < k) {
      k -= ile;
      flip = 1;
      wyn |= mm;
    }
    int ga0 = n;
    int gb0 = n;
    int ga1 = 1;
    int gb1 = 1;
    nileP = 0;
    for (int it = 0; it < ileP; ++it) {
      const node &u = sPoz[it];
      int a1p = ga1;
      int a0k = ga0;
      for (int j = u.ap; j <= u.ak; ++j) {
        int v = sA[j];
        if (h[v] & mm) {
          nA[ga1++] = v;
        } else {
          nA[ga0--] = v;
        }
      }
      int a1k = ga1 - 1;
      int a0p = ga0 + 1;
      int b1p = gb1;
      int b0k = gb0;
      for (int j = u.bp; j <= u.bk; ++j) {
        int v = sB[j];
        if (h[v] & mm) {
          nB[gb1++] = v;
        } else {
          nB[gb0--] = v;
        }
      }
      int b1k = gb1 - 1;
      int b0p = gb0 + 1;
      if (!flip) {
        if (a0p <= a0k && b0p <= b0k) nPoz[nileP++] = node(a0p, a0k, b0p, b0k);
        if (a1p <= a1k && b1p <= b1k) nPoz[nileP++] = node(a1p, a1k, b1p, b1k);
      } else {
        if (a0p <= a0k && b1p <= b1k) nPoz[nileP++] = node(a0p, a0k, b1p, b1k);
        if (a1p <= a1k && b0p <= b0k) nPoz[nileP++] = node(a1p, a1k, b0p, b0k);
      }
    }
  }
  printf("%lld\n", wyn);
  return 0;
}
