# Pythonは低速なので通るわけがない class BinaryTrie: def __init__(self, log): self.lg = log self.b0 = [-1] self.b1 = [-1] self.cnt = [0] def __append(self, p, nxt_bit): idx = len(self.cnt) self.b0.append(-1) self.b1.append(-1) self.cnt.append(0) if nxt_bit: self.b1[p] = idx else: self.b0[p] = idx return idx def move(self, p, nxt_bit): if nxt_bit: if self.b1[p] == -1: return self.__append(p, nxt_bit) return self.b1[p] else: if self.b0[p] == -1: return self.__append(p, nxt_bit) return self.b0[p] def subtree_cnt(self, r): if r == -1: return 0 return self.cnt[r] def add_value(self, x): r = 0 self.cnt[r] += 1 for i in range(self.lg, -1, -1): r = self.move(r, (x>>i)&1) self.cnt[r] += 1 def lower_bound(self, value, x=0): lb = 0 r = 0 for i in range(self.lg, -1, -1): if self.cnt[r] == 0: return lb nxt_bit = (value>>i)&1 flip = (x>>i)&1 if nxt_bit: if flip: lb += self.subtree_cnt(self.b1[r]) else: lb += self.subtree_cnt(self.b0[r]) if nxt_bit^flip == 0 and self.b0[r] == -1: return lb if nxt_bit^flip == 1 and self.b1[r] == -1: return lb r = self.move(r, nxt_bit^flip) return lb def upper_bound(self, value, x=0): ub = 0 r = 0 for i in range(self.lg, -1, -1): if self.cnt[r] == 0: return ub nxt_bit = (value>>i)&1 flip = (x>>i)&1 if nxt_bit: if flip: ub += self.subtree_cnt(self.b1[r]) else: ub += self.subtree_cnt(self.b0[r]) if nxt_bit^flip == 0 and self.b0[r] == -1: return ub if nxt_bit^flip == 1 and self.b1[r] == -1: return ub r = self.move(r, nxt_bit^flip) ub += self.subtree_cnt(r) return ub n, k = map(int, input().split()) bt = BinaryTrie(30) a = list(map(int, input().split())) for v in a: bt.add_value(v) pos = n + 2 * k - 1 ng, ok = -1, (1 << 30) - 1 while ok - ng > 1: x = (ok + ng) >> 1 count = 0 for i in range(n): count += bt.upper_bound(x, a[i]) if count >= pos: break if count >= pos: ok = x else: ng = x print(ok)