← Home
package main

import (
	"fmt"
	"io"
	"os"
	"sort"
)

type uint64Slice []uint64

func (x uint64Slice) Len() int           { return len(x) }
func (x uint64Slice) Less(i, j int) bool { return x[i] < x[j] }
func (x uint64Slice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func findSplit(D []uint64, L, R int, b int) int {
	low, high := L, R
	for low < high {
		mid := low + (high-low)/2
		if (D[mid]>>b)&1 == 1 {
			high = mid
		} else {
			low = mid + 1
		}
	}
	return low
}

func main() {
	input, _ := io.ReadAll(os.Stdin)
	offset := 0

	readInt := func() int {
		res := 0
		for offset < len(input) && input[offset] < '0' {
			offset++
		}
		for offset < len(input) && input[offset] >= '0' && input[offset] <= '9' {
			res = res*10 + int(input[offset]-'0')
			offset++
		}
		return res
	}

	readUint64 := func() uint64 {
		var res uint64 = 0
		for offset < len(input) && input[offset] < '0' {
			offset++
		}
		for offset < len(input) && input[offset] >= '0' && input[offset] <= '9' {
			res = res*10 + uint64(input[offset]-'0')
			offset++
		}
		return res
	}

	n := readInt()
	var k int64
	{
		var res int64 = 0
		for offset < len(input) && input[offset] < '0' {
			offset++
		}
		for offset < len(input) && input[offset] >= '0' && input[offset] <= '9' {
			res = res*10 + int64(input[offset]-'0')
			offset++
		}
		k = res
	}

	if n == 0 {
		return
	}

	D := make([]uint64, n)
	D[0] = 0

	for i := 1; i < n; i++ {
		p := readInt()
		w := readUint64()
		D[i] = D[p-1] ^ w
	}

	sort.Sort(uint64Slice(D))

	L_arr := make([]int, n)
	R_arr := make([]int, n)
	for i := 0; i < n; i++ {
		L_arr[i] = 0
		R_arr[i] = n
	}

	M_cache := make([]int, n)
	for i := 0; i < n; i++ {
		M_cache[i] = -1
	}
	modified := make([]int, 0, n)

	var ans uint64 = 0

	for b := 61; b >= 0; b-- {
		var count int64 = 0
		for i := 0; i < n; i++ {
			L := L_arr[i]
			R := R_arr[i]
			if L == R {
				continue
			}
			M := M_cache[L]
			if M == -1 {
				M = findSplit(D, L, R, b)
				M_cache[L] = M
				modified = append(modified, L)
			}

			c := (D[i] >> b) & 1
			if c == 0 {
				count += int64(M - L)
			} else {
				count += int64(R - M)
			}
		}

		bit := uint64(0)
		if count < k {
			bit = 1
			k -= count
		}

		ans |= (bit << b)

		for i := 0; i < n; i++ {
			L := L_arr[i]
			R := R_arr[i]
			if L == R {
				continue
			}
			M := M_cache[L]
			c := (D[i] >> b) & 1
			if bit == 0 {
				if c == 0 {
					R_arr[i] = M
				} else {
					L_arr[i] = M
				}
			} else {
				if c == 0 {
					L_arr[i] = M
				} else {
					R_arr[i] = M
				}
			}
		}

		for _, L := range modified {
			M_cache[L] = -1
		}
		modified = modified[:0]
	}

	fmt.Println(ans)
}