n, k = list(map(int, input().split()))

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



ruiseki = [0] * (n + 1)

for i in range(n):

    ruiseki[i+1] = ruiseki[i] + a[i]



li = []

for i in range(n):

    for j in range(i, n):

        tmp = format(ruiseki[j + 1] - ruiseki[i], '040b')

        li.append(tmp)



for i in range(40):

    cnt = 0

    new_li = []

    for j in range(len(li)):

        if li[j][i] == "1":

            new_li.append(li[j])

            cnt += 1

    if cnt >= k:

        li = new_li[0:]



ans = 2**41 -1

for i in range(k):

    ans = ans & int(li[i], 2)

print(ans)
n, k = list(map(int, input().split()))

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





li = []

for i in range(n):

    num = 0

    for j in range(i, n):

        num += a[j]

        li.append(num)



ans = 0

for i in range(40)[::-1]:

    bit = 2 ** i

    new_li = [num for num in li if num&bit != 0]

    if len(new_li) >= k:

        li = new_li[0:]

        ans += bit

print(ans)
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + a[i]
li = []
for i in range(n):
    for j in range(i, n):
        tmp = format(ruiseki[j + 1] - ruiseki[i], "040b")
        li.append(tmp)
for i in range(40):
    cnt = 0
    new_li = []
    for j in range(len(li)):
        if li[j][i] == "1":
            new_li.append(li[j])
            cnt += 1
    if cnt >= k:
        li = new_li[0:]
ans = 2**41 - 1
for i in range(k):
    ans = ans & int(li[i], 2)
print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
li = []
for i in range(n):
    num = 0
    for j in range(i, n):
        num += a[j]
        li.append(num)
ans = 0
for i in range(40)[::-1]:
    bit = 2**i
    new_li = [num for num in li if num & bit != 0]
    if len(new_li) >= k:
        li = new_li[0:]
        ans += bit
print(ans)

-ruiseki = [0] * (n + 1) -for i in range(n): -    ruiseki[i + 1] = ruiseki[i] + a[i] +    num = 0 -        tmp = format(ruiseki[j + 1] - ruiseki[i], "040b") -        li.append(tmp) -for i in range(40): -    cnt = 0 -    new_li = [] -    for j in range(len(li)): -        if li[j][i] == "1": -            new_li.append(li[j]) -            cnt += 1 -    if cnt >= k: +        num += a[j] +        li.append(num) +ans = 0 +for i in range(40)[::-1]: +    bit = 2**i +    new_li = [num for num in li if num & bit != 0] +    if len(new_li) >= k: -ans = 2**41 - 1 -for i in range(k): -    ans = ans & int(li[i], 2) +        ans += bit