import itertools as iter

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

beauty_list = []
for i in range(len(a) + 1):
    for element in iter.combinations(a, i):
        beauty = sum(element)
        beauty_list.append(beauty)

max_and = 0
for combi in iter.combinations(set(beauty_list), k):
    ans = combi[0]
    for element in combi:
        ans &= element
    if ans > max_and:
        max_and = ans

print(max_and)
