from collections import defaultdict N,K=map(int,input().split()) K-=1 A=list(map(int,input().split())) exp2=[2**i for i in range(35)] left_sum=0 left=0 ans=0 for i in range(29,-1,-1): left+=exp2[i] dic=defaultdict(int) for j in range(N): dic[A[j]&(left)]+=1 tmp_sum=left_sum keys = list(dic.keys()) for k in keys: if k==k^ans: tmp_sum+=dic[k]*(dic[k^ans]-1) else: tmp_sum+=dic[k]*(dic[k^ans]) if tmp_sum<=K*2: ans+=exp2[i] left_sum=tmp_sum print(ans)