

def main():

    from itertools import accumulate

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

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



    accA = [0] + list(accumulate(A))

    Bin = []



    for i in range(N + 1):

        for j in range(i + 1, N + 1):

            par_sum = accA[j] - accA[i]

            b = bin(par_sum)

            b = b[2:].zfill(40)

            Bin.append(b)



    ans = 0

    for n in range(40):

        sifted_B = [b for b in Bin if b[n] == "1"]

        if len(sifted_B) >= K:

            ans += 2 ** (39 - n)

            Bin = sifted_B



    print(ans)



    

main()

from itertools import accumulate

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

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





# 連続する部分列の和を計算

A_acc = [0] + list(accumulate(A))

SubArraysSums = []

for i in range(1, N + 1):

    for j in range(i, N + 1):

        SubArraysSums.append(A_acc[j] - A_acc[i - 1])

SubArraysSums.sort()





ans = 0

tmp = []

for i in reversed(list(range(40))):

    for s in SubArraysSums:

        if (1 << i) & s:

            tmp.append(s)



    if len(tmp) >= K:

        ans += (1 << i)

        SubArraysSums = tmp

    tmp = []



print(ans)

def main():
    from itertools import accumulate

    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    accA = [0] + list(accumulate(A))
    Bin = []
    for i in range(N + 1):
        for j in range(i + 1, N + 1):
            par_sum = accA[j] - accA[i]
            b = bin(par_sum)
            b = b[2:].zfill(40)
            Bin.append(b)
    ans = 0
    for n in range(40):
        sifted_B = [b for b in Bin if b[n] == "1"]
        if len(sifted_B) >= K:
            ans += 2 ** (39 - n)
            Bin = sifted_B
    print(ans)


main()

from itertools import accumulate

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
# 連続する部分列の和を計算
A_acc = [0] + list(accumulate(A))
SubArraysSums = []
for i in range(1, N + 1):
    for j in range(i, N + 1):
        SubArraysSums.append(A_acc[j] - A_acc[i - 1])
SubArraysSums.sort()
ans = 0
tmp = []
for i in reversed(list(range(40))):
    for s in SubArraysSums:
        if (1 << i) & s:
            tmp.append(s)
    if len(tmp) >= K:
        ans += 1 << i
        SubArraysSums = tmp
    tmp = []
print(ans)

-def main(): -    from itertools import accumulate +from itertools import accumulate -    N, K = list(map(int, input().split())) -    A = list(map(int, input().split())) -    accA = [0] + list(accumulate(A)) -    Bin = [] -    for i in range(N + 1): -        for j in range(i + 1, N + 1): -            par_sum = accA[j] - accA[i] -            b = bin(par_sum) -            b = b[2:].zfill(40) -            Bin.append(b) -    ans = 0 -    for n in range(40): -        sifted_B = [b for b in Bin if b[n] == "1"] -        if len(sifted_B) >= K: -            ans += 2 ** (39 - n) -            Bin = sifted_B -    print(ans) - - -main() +N, K = list(map(int, input().split())) +A = list(map(int, input().split())) +# 連続する部分列の和を計算 +A_acc = [0] + list(accumulate(A)) +SubArraysSums = [] +for i in range(1, N + 1): +    for j in range(i, N + 1): +        SubArraysSums.append(A_acc[j] - A_acc[i - 1]) +SubArraysSums.sort() +ans = 0 +tmp = [] +for i in reversed(list(range(40))): +    for s in SubArraysSums: +        if (1 << i) & s: +            tmp.append(s) +    if len(tmp) >= K: +        ans += 1 << i +        SubArraysSums = tmp +    tmp = [] +print(ans)