#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
bool minimize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x > y + eps) {
    x = y;
    return true;
  } else
    return false;
}
template <class X, class Y>
bool maximize(X &x, const Y &y) {
  X eps = 1e-9;
  if (x + eps < y) {
    x = y;
    return true;
  } else
    return false;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
const int BASE = (1LL << (8));
struct Number {
  unsigned char d[3];
  Number(int x = 0) {
    for (int i = 0, _n = (3); i < _n; i++) {
      d[i] = x & 255;
      x >>= 8;
    }
  }
  Number operator+(const Number &x) const {
    Number res;
    int rem = 0;
    for (int i = 0, _n = (3); i < _n; i++) {
      int tmp = rem + d[i] + x.d[i];
      res.d[i] = tmp & 255;
      rem = tmp > 255;
    }
    return res;
  }
  Number operator-(const Number &x) const {
    Number res;
    int rem = 0;
    for (int i = 0, _n = (3); i < _n; i++) {
      int tmp = d[i] - rem - x.d[i];
      res.d[i] = tmp < 0 ? tmp + BASE : tmp;
      rem = tmp < 0;
    }
    return res;
  }
  bool operator==(const Number &x) const {
    for (int i = 0, _n = (3); i < _n; i++)
      if (d[i] != x.d[i]) return false;
    return true;
  }
  int value(void) const {
    int res = 0;
    for (int i = (2), _a = (0); i >= _a; i--) res = (res << 8) ^ d[i];
    return res;
  }
};
long long value[1000100], asked;
int ___left[1000100], ___right[1000100], n;
Number numZero[62][1000100];
void loadTree(void) {
  cin >> n >> asked;
  for (int i = (2), _b = (n); i <= _b; i++) {
    int p;
    long long w;
    cin >> p >> w;
    value[i] = value[p] ^ w;
  }
}
void prepare(void) {
  sort(value + 1, value + n + 1);
  for (int j = 0, _n = (62); j < _n; j++)
    for (int i = (1), _b = (n); i <= _b; i++) {
      numZero[j][i] = numZero[j][i - 1];
      if (!(((value[i]) >> (j)) & 1)) numZero[j][i] = numZero[j][i] + 1;
    }
  for (int i = (1), _b = (n); i <= _b; i++) ___right[i] = n;
}
void process(void) {
  long long res = 0;
  for (int pos = (62 - 1), _a = (0); pos >= _a; pos--) {
    long long total = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      int bit = (((value[i]) >> (pos)) & 1);
      int zero = (numZero[pos][___right[i]] - numZero[pos][___left[i]]).value();
      int need = bit == 0 ? zero : ___right[i] - ___left[i] - zero;
      total += need;
      if (total > asked) break;
    }
    int newBit = total >= asked ? 0 : 1;
    if (asked > total) asked -= total;
    res |= (1LL * newBit) << pos;
    for (int i = (1), _b = (n); i <= _b; i++) {
      int need = newBit ^ (((value[i]) >> (pos)) & 1);
      int zero = (numZero[pos][___right[i]] - numZero[pos][___left[i]]).value();
      if (need == 1)
        ___left[i] += zero;
      else
        ___right[i] = ___left[i] + zero;
    }
  }
  cout << res << endl;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  loadTree();
  prepare();
  process();
  return 0;
}
