def walsh_hadamard_transform(f): k = (len(f) - 1).bit_length() h = 1 for _ in range(k): for i in range(0, len(f), h * 2): for j in range(i, i + h): f[j], f[j + h] = f[j] + f[j + h], f[j] - f[j + h] h *= 2 def Xor_convolution(a, b): f = a[:] g = b[:] k = (len(f) - 1).bit_length() walsh_hadamard_transform(f) walsh_hadamard_transform(g) for i in range(1 << k): f[i] = f[i] * g[i] walsh_hadamard_transform(f) for i in range(len(f)): f[i] >>= k return f N, K = map(int, input().split()) A = list(map(int, input().split())) F = [0 for i in range(1 << 15)] for a in A: F[a >> 15] += 1 F = Xor_convolution(F, F) F[0] -= N for i in range(1 << 15): F[i] //= 2 if i > 0: F[i] += F[i - 1] i = 0 while F[i] < K: i += 1 mask = i ans = i << 15 if i > 0: K -= F[i - 1] G = [[] for i in range(1 << 15)] for a in A: b = a >> 15 G[b].append(a - (b << 15)) F = [0 for i in range(1 << 15)] for i in range(1 << 15): c = min(len(G[i]), len(G[mask ^ i])) if c <= 1024: for j in G[i]: for k in G[i ^ mask]: F[j ^ k] += 1 else: f, g = [0 for _ in range(1 << 15)], [0 for _ in range(1 << 15)] for j in G[i]: f[j] += 1 for k in G[i ^ mask]: g[k] += 1 f = Xor_convolution(f, g) for j in range(1 << 15): F[j] += f[j] if mask == 0: F[0] -= N for i in range(1 << 15): F[i] //= 2 if i > 0: F[i] += F[i - 1] i = 0 while F[i] < K: i += 1 ans += i print(ans)