import itertools
n,d = map(int,input().split())
a = list(map(int,input().split()))

b = []
c = 0
m = n
for i in range(n):
    for j in range(m):
        for k in range(j+1):
            c += a[k]
        b.append(c)
        c = 0
    m -= 1
    del a[0]
b = list(set(b))

h = list(itertools.permutations(range(len(b)), d))
p = []
q = []
for i in range(len(h)):
    for j in range(d):
        p.append(b[h[i][j]])
        
    for k in range(d-1):
        k += 1
        if k == 1:
            e = bin(p[k])
            f = bin(p[k-1])
            g = int(e,0) & int(f,0)
        g = int(bin(g),0) & int(bin(p[k]),0)
    q.append(g)
    p = []

print(max(q))