from copy import deepcopy

from collections import deque

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

A = [int(a) for a in input().split()]

Sum = deque([0])

for i in range(N):

    Sum.append(Sum[-1] + A[i])

Asum = deque([])

for i in range(N):

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

        Asum.append(Sum[j] - Sum[i])



Search = deepcopy(Asum)

x = 0

for i in reversed(list(range(1, 41))):

    new = deque([])

    for s in Search:

        if (x + 2 ** (i-1)) & s == x + 2 ** (i-1):

            new.append(s)

    if len(new) >= K:

        Search = new

        x += 2 ** (i-1)

print(x)
import sys

sys.setrecursionlimit(1000000)



def search(i, L, Lnum, K):

    if i > 40: return 0

    add = pow(2, 40 - i)

    nextK = []

    count = 0

    for l in L:

        if l & add == add:

            nextK.append(l)

            count += 1

    #print(i, L)

    if count >= K: return add + search(i+1, nextK, count, K)

    else: return search(i+1, L, Lnum, K)





def solve():

    input = sys.stdin.readline

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

    A = [int(a) for a in input().split()]

    sumA = [0] * (N + 1)

    for i, a in enumerate(A): sumA[i+1] = sumA[i] + a

    subA = []

 

    for i in range(N):

        for j in range(i+1, N+1): subA.append(sumA[j] - sumA[i])



    print((search(0, subA, N * (N + 1) // 2, K)))



    return 0



if __name__ == "__main__":

    solve()
from copy import deepcopy
from collections import deque

N, K = list(map(int, input().split()))
A = [int(a) for a in input().split()]
Sum = deque([0])
for i in range(N):
    Sum.append(Sum[-1] + A[i])
Asum = deque([])
for i in range(N):
    for j in range(i + 1, N + 1):
        Asum.append(Sum[j] - Sum[i])
Search = deepcopy(Asum)
x = 0
for i in reversed(list(range(1, 41))):
    new = deque([])
    for s in Search:
        if (x + 2 ** (i - 1)) & s == x + 2 ** (i - 1):
            new.append(s)
    if len(new) >= K:
        Search = new
        x += 2 ** (i - 1)
print(x)

import sys

sys.setrecursionlimit(1000000)


def search(i, L, Lnum, K):
    if i > 40:
        return 0
    add = pow(2, 40 - i)
    nextK = []
    count = 0
    for l in L:
        if l & add == add:
            nextK.append(l)
            count += 1
    # print(i, L)
    if count >= K:
        return add + search(i + 1, nextK, count, K)
    else:
        return search(i + 1, L, Lnum, K)


def solve():
    input = sys.stdin.readline
    N, K = list(map(int, input().split()))
    A = [int(a) for a in input().split()]
    sumA = [0] * (N + 1)
    for i, a in enumerate(A):
        sumA[i + 1] = sumA[i] + a
    subA = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            subA.append(sumA[j] - sumA[i])
    print((search(0, subA, N * (N + 1) // 2, K)))
    return 0


if __name__ == "__main__":
    solve()

-from copy import deepcopy -from collections import deque +import sys -N, K = list(map(int, input().split())) -A = [int(a) for a in input().split()] -Sum = deque([0]) -for i in range(N): -    Sum.append(Sum[-1] + A[i]) -Asum = deque([]) -for i in range(N): -    for j in range(i + 1, N + 1): -        Asum.append(Sum[j] - Sum[i]) -Search = deepcopy(Asum) -x = 0 -for i in reversed(list(range(1, 41))): -    new = deque([]) -    for s in Search: -        if (x + 2 ** (i - 1)) & s == x + 2 ** (i - 1): -            new.append(s) -    if len(new) >= K: -        Search = new -        x += 2 ** (i - 1) -print(x) +sys.setrecursionlimit(1000000) + + +def search(i, L, Lnum, K): +    if i > 40: +        return 0 +    add = pow(2, 40 - i) +    nextK = [] +    count = 0 +    for l in L: +        if l & add == add: +            nextK.append(l) +            count += 1 +    # print(i, L) +    if count >= K: +        return add + search(i + 1, nextK, count, K) +    else: +        return search(i + 1, L, Lnum, K) + + +def solve(): +    input = sys.stdin.readline +    N, K = list(map(int, input().split())) +    A = [int(a) for a in input().split()] +    sumA = [0] * (N + 1) +    for i, a in enumerate(A): +        sumA[i + 1] = sumA[i] + a +    subA = [] +    for i in range(N): +        for j in range(i + 1, N + 1): +            subA.append(sumA[j] - sumA[i]) +    print((search(0, subA, N * (N + 1) // 2, K))) +    return 0 + + +if __name__ == "__main__": +    solve()