#include <bits/stdc++.h>
using namespace std;
template <typename T>
void radix_sort(vector<T> &numbers, int bits_per_pass = 10) {
  if (numbers.size() < 256) {
    sort(numbers.begin(), numbers.end());
    return;
  }
  T minimum = *min_element(numbers.begin(), numbers.end());
  int max_bits = 0;
  for (T &x : numbers)
    max_bits =
        max(max_bits, x == minimum ? 0 : 64 - __builtin_clzll(x - minimum));
  int passes = max((max_bits + bits_per_pass / 2) / bits_per_pass, 1);
  if (32 - __builtin_clz(numbers.size()) <= 1.5 * passes) {
    sort(numbers.begin(), numbers.end());
    return;
  }
  if (minimum < 0) {
    for (T &x : numbers) x -= minimum;
  }
  vector<T> buffer(numbers.size());
  vector<int> counts;
  int bits_so_far = 0;
  for (int p = 0; p < passes; p++) {
    int bits = (max_bits + p) / passes;
    counts.assign(1 << bits, 0);
    for (T &x : numbers) counts[(x >> bits_so_far) & ((1 << bits) - 1)]++;
    int count_sum = 0;
    for (int &count : counts) {
      int current = count;
      count = count_sum;
      count_sum += current;
    }
    for (T &x : numbers) {
      int key = (x >> bits_so_far) & ((1 << bits) - 1);
      buffer[counts[key]++] = x;
    }
    swap(numbers, buffer);
    bits_so_far += bits;
  }
  if (minimum < 0) {
    for (T &x : numbers) x += minimum;
  }
}
const int BITS = 62;
int N;
long long K;
vector<int> parent;
vector<long long> up_weight, root_xor;
vector<long long> first, second;
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;
  }
  radix_sort(second);
  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]) pos++;
    while (pos < N && 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];
  }
  radix_sort(root_xor);
  long long answer = 0;
  for (int bit = BITS - 1; bit >= 0; bit--) {
    long long count = starting_with(answer >> bit, bit);
    if (K > count) {
      K -= count;
      answer += 1LL << bit;
    }
  }
  printf("%lld\n", answer);
}
