N, K = map(int, input().split()) A = list(map(int, input().split())) C = [dict() for _ in range(30)] for i in range(N): for j in range(30): key = A[i] & ~((1<<(30-j))-1) bit = 1&A[i]>>(29-j) if (key, bit) in C[j]: C[j][(key, bit)] += 1 else: C[j][(key, bit)] = 1 ans = 0 cnt = 0 flag = False for i in range(30): c = 0 for j in range(N): key = (ans^A[j]) & ~((1<<(30-i))-1) bit = 1&A[j]>>(29-i) if (key, bit) in C[i]: c += C[i][(key, bit)] if ans == 0: c -= 1 c //= 2 if cnt+c < K: ans |= 1<<(29-i) cnt += c print(ans)