#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, D = 61;
vector<int> v[N];
long long w[N];
struct Node {
  int l, r, x, s;
  Node(int l, int r, int x) : l(l), r(r), x(x) { s = r - l + 1; }
  pair<Node, Node> getPair() {
    int m = l;
    while (m <= r && !((w[m] >> x) & 1)) m++;
    return {Node(l, m - 1, x - 1), Node(m, r, x - 1)};
  }
};
vector<pair<Node, Node>> t[2];
void dfs(int node, int anc) {
  for (int to : v[node]) {
    if (to != anc) {
      w[to] ^= w[node];
      dfs(to, node);
    }
  }
}
int main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d%lld", &p, &w[i]);
    p--;
    v[p].push_back(i);
  }
  dfs(0, -1);
  sort(w, w + n);
  long long x = 0;
  int c = 0;
  t[c].push_back({Node(0, n - 1, D), Node(0, n - 1, D)});
  for (int i = D; i >= 0; i--, c = 1 - c) {
    t[1 - c].clear();
    long long ct = 0;
    for (int j = 0; j < t[c].size(); j++) {
      auto p = t[c][j].first.getPair(), q = t[c][j].second.getPair();
      ct +=
          p.first.s * (long long)q.first.s + p.second.s * (long long)q.second.s;
    }
    if (k > ct) {
      k -= ct;
      x |= 1ll << i;
      for (int j = 0; j < t[c].size(); j++) {
        auto p = t[c][j].first.getPair(), q = t[c][j].second.getPair();
        if (p.first.s && q.second.s) t[1 - c].push_back({p.first, q.second});
        if (p.second.s && q.first.s) t[1 - c].push_back({p.second, q.first});
      }
    } else {
      for (int j = 0; j < t[c].size(); j++) {
        auto p = t[c][j].first.getPair(), q = t[c][j].second.getPair();
        if (p.first.s && q.first.s) t[1 - c].push_back({p.first, q.first});
        if (p.second.s && q.second.s) t[1 - c].push_back({p.second, q.second});
      }
    }
  }
  printf("%lld", x);
  return 0;
}
