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

count, sum, start = 0, 0, 0
substring = []
while (True):
    sum += input[count]
    substring.append(sum)
    if start == len(input) - 1:
        break
    if count == len(input) - 1:
        start += 1
        count = start
        sum = 0
        continue

    count += 1
substring.sort(reverse=True)

result = substring[0]
for i in range(1, K):
    result = result & substring[i]

print(result)
