#include <bits/stdc++.h>
using namespace std;
const int BITS = 62;
const int TABLE = 21;
int N;
long long K;
vector<int> parent;
vector<long long> up_weight, root_xor;
vector<long long> first, second;
vector<int> table(1 << TABLE);
long long starting_with(long long value, int lowest_bit) {
  first.resize(N);
  second.resize(N);
  long long total = 0;
  for (int i = 0; i < N; i++) {
    first[i] = root_xor[i] >> lowest_bit;
    second[i] = first[i] ^ value;
  }
  if (BITS - lowest_bit <= TABLE) {
    table.assign(1 << TABLE, 0);
    for (int i = 0; i < N; i++) table[first[i]]++;
    for (int i = 0; i < N; i++) total += table[second[i]];
    return total;
  }
  sort(second.begin(), second.end());
  int pos = 0;
  for (int i = 0, j = 0; i < N; i = j) {
    while (j < N && first[i] == first[j]) j++;
    while (pos < N && second[pos] <= first[i]) {
      if (second[pos] == first[i]) total += j - i;
      pos++;
    }
  }
  return total;
}
int main() {
  scanf("%d %lld", &N, &K);
  parent.assign(N, -1);
  up_weight.assign(N, 0);
  root_xor.assign(N, 0);
  for (int i = 1; i < N; i++) {
    scanf("%d %lld", &parent[i], &up_weight[i]);
    parent[i]--;
    root_xor[i] = root_xor[parent[i]] ^ up_weight[i];
  }
  sort(root_xor.begin(), root_xor.end());
  long long answer = 0;
  for (int bit = BITS - 1; bit >= 0; bit--) {
    long long count = starting_with(answer >> bit, bit);
    if (K <= count) {
      continue;
    } else {
      K -= count;
      answer += 1LL << bit;
    }
  }
  printf("%lld\n", answer);
}
