class Trie: def __init__(self, N): self.tree = [[-1]*2 for _ in range(N+1)] self.arrive = [0]*(N+1) self.last = [0]*(N+1) self.nex = 1 self.cnt = 0 def insert(self, S): self.cnt += 1 now = 0 for i in range(30): b = 1&S>>(29-i) if self.tree[now][b] == -1: self.tree[now][b] = self.nex now = self.nex self.nex += 1 else: now = self.tree[now][b] self.arrive[now] += 1 self.last[now] += 1 def query(self, MAX, S): now = 0 ans = 0 xor = MAX^S for i in range(30): b = 1 & S>>(29-i) if 1<<(29-i) & MAX: if b == 0 and self.tree[now][0] != -1: ans += self.arrive[self.tree[now][0]] elif b == 1 and self.tree[now][1] != -1: ans += self.arrive[self.tree[now][1]] b2 = 1 & xor>>(29-i) if self.tree[now][b2] != -1: now = self.tree[now][b2] else: break return ans N, K = map(int, input().split()) A = list(map(int, input().split())) def func(n): T = Trie(N*30) ans = 0 for i in reversed(range(N)): T.insert(A[i]) ans += T.query(n, A[i])-1 return ans left = 0 right = (1<<30)-1 while left+1 < right: mid = (left+right)//2 if func(mid) < K: left = mid else: right = mid print(right-1)