import sys input = lambda: sys.stdin.readline().rstrip() def count01(L, i): czero, cone = 0, 0 for a in L: if (a >> i) & 1: cone += 1 else: czero += 1 return czero, cone def div01(L, i): rzero, rone = [], [] for a in L: (rone if (a >> i) & 1 else rzero).append(a) return rzero, rone def main(): # 入力 N, K = map(int, input().split()) A = list(map(int, input().split())) # 計算・出力 # 0 <= i, j < N で考える K -= 1 K *= 2 K += N pairs = [[A, A]] # 候補となる数の組 ans = 0 for i in range(29, -1, -1): ans <<= 1 czero = 0 for l, r in pairs: lz, lo = count01(l, i) rz, ro = count01(r, i) czero += lz * rz + lo * ro npairs = [] if K >= czero: ans += 1 K -= czero for l, r in pairs: lz, lo = div01(l, i) rz, ro = div01(r, i) if len(lz) > 0 and len(ro) > 0: npairs.append([lz, ro]) if len(lo) > 0 and len(rz) > 0: npairs.append([lo, rz]) else: for l, r in pairs: lz, lo = div01(l, i) rz, ro = div01(r, i) if len(lz) > 0 and len(rz) > 0: npairs.append([lz, rz]) if len(lo) > 0 and len(ro) > 0: npairs.append([lo, ro]) pairs = npairs print(ans) if __name__ == "__main__": main()