#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 i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const unsigned long long ONE = 1;
int main() {
  int T = 30;
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  vector<unsigned long long> a(n), on(n);
  for (int i = 1; i < n; ++i) {
    int par;
    long long x;
    scanf("%d%llu", &par, &x);
    a[i] = a[par - 1] ^ x;
  }
  debug() << " ["
          << "a"
             ": "
          << (a) << "] ";
  long long count_smaller = 0;
  unsigned long long answer = 0;
  vector<unsigned long long> A(n);
  vector<pair<unsigned long long, unsigned long long>> B(n), tmp(n);
  for (int i = 0; i < n; ++i) {
    B[i] = make_pair(0ULL, a[i]);
  }
  sort(B.begin(), B.end());
  vector<unsigned long long> sorted = a;
  sort(sorted.begin(), sorted.end());
  for (int bit = 63; bit >= 0; --bit) {
    const unsigned long long ONLY = ONE << bit;
    answer |= ONLY;
    for (int i = 0; i < n; ++i) {
      if (a[i] & ONLY) {
        on[i] |= ONLY;
      }
      if (sorted[i] & ONLY) {
        A[i] |= ONLY;
      }
    }
    long long nowe = 0;
    for (int i = 0; i < n; ++i) {
      int type = T / 16 % 4;
      if (type == 3 || bool(B[i].second & ONLY) == type) {
        B[i].first ^= ONLY;
      }
    }
    auto ple = [&]() {
      for (int i = 0; i < n - 1; ++i) {
        if (B[i].first > B[i + 1].first) {
          int nxt = 0;
          int start = i;
          while (start - 1 >= 0 && B[start - 1].first == B[start].first) {
            --start;
          }
          int en = i + 1;
          while (en + 1 < n && B[en].first == B[en + 1].first) {
            ++en;
          }
          for (int j = start; j <= i; ++j) {
            tmp[nxt++] = B[j];
          }
          nxt = start;
          for (int j = i + 1; j <= en; ++j) {
            B[nxt++] = B[j];
          }
          for (int j = nxt; j <= en; ++j) {
            B[j] = tmp[j - nxt];
          }
        }
      }
    };
    ple();
    int j = 0;
    for (int i = 0; i < n; ++i) {
      int cnt = 1;
      while (i + 1 < n && A[i] == A[i + 1]) {
        ++i;
        ++cnt;
      }
      while (j < n && B[j].first < A[i]) {
        ++j;
      }
      while (j < n && B[j].first == A[i]) {
        ++j;
        nowe += cnt;
      }
    }
    if (count_smaller + nowe < k) {
      count_smaller += nowe;
      for (int i = 0; i < n; ++i) {
        int type = T / 4 % 4;
        if (type == 3 || bool(B[i].second & ONLY) == type) {
          B[i].first ^= ONLY;
        }
      }
    } else {
      answer ^= ONLY;
      for (int i = 0; i < n; ++i) {
        int type = T % 4;
        if (type == 3 || bool(B[i].second & ONLY) == type) {
          B[i].first ^= ONLY;
        }
      }
    }
    ple();
  }
  printf("%lld\n", answer);
}
