N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))

b.sort()
b=b[::-1]
for sp in range(0,N+1-K):
    if [len(bin(b[i])[2:]) for i in range(sp,sp+K)] == [len(bin(b[sp])[2:])for i in range(sp,sp+K)]:
        break
s=b[sp:sp+K]
if K==1:
    tmp=s[0]
else:
    tmp=s[0]&s[1]
    for i in range(2,K):
        tmp=tmp&s[i]

print(tmp)