import sys input = lambda: sys.stdin.readline().rstrip() 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 divs = [] for l, r in pairs: ld, rd = div01(l, i), div01(r, i) divs.append([ld, rd]) lz, lo, rz, ro = len(ld[0]), len(ld[1]), len(rd[0]), len(rd[1]) czero += lz * rz + lo * ro npairs = [] if K >= czero: ans += 1 K -= czero for ld, rd in divs: if len(ld[0]) > 0 and len(rd[1]) > 0: npairs.append([ld[0], rd[1]]) if len(ld[1]) > 0 and len(rd[0]) > 0: npairs.append([ld[1], rd[0]]) else: for ld, rd in divs: if len(ld[0]) > 0 and len(rd[0]) > 0: npairs.append([ld[0], rd[0]]) if len(ld[1]) > 0 and len(rd[1]) > 0: npairs.append([ld[1], rd[1]]) pairs = npairs # print(K, czero, pairs) print(ans) if __name__ == "__main__": main()