Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He wants to find the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. Constraints: 2 ≤ N ≤ 1000, 1 ≤ a_i ≤ 10^9, 1 ≤ K ≤ N(N+1)/2. Input format: N K, followed by the sequence a_1 to a_N. Output the answer. Example: Input: 4 2, 2 5 2 5. Output: 12.

# Buggy version:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n,k = ma()
A = lma()
bu = []
for i in range(n):
    tmp=0
    for j in range(i,n):
        tmp+=A[j]
        bu.append(tmp)
mb = bin(max(bu))
ans = 0
for i in range(len(mb)-3,-1,-1):
    tmp=[]
    for b in bu:
        if (b>>i &1):
            tmp.append(b)
    if len(tmp2)>=k:
        ans+=2**i
        bu=tmp
    else:
        pass
print(ans)


# Fixed version:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n,k = ma()
A = lma()
bu = []
for i in range(n):
    tmp=0
    for j in range(i,n):
        tmp+=A[j]
        bu.append(tmp)
mb = bin(max(bu))
ls = [0]*(len(mb)-2)
for b in bu:
    for i in range(len(bin(b))-2):
        if (b>>i &1):
            ls[i]+=1
ans = 0
tmp=bu
for i in range(len(mb)-3,-1,-1):
    if ls[i]<k:
        continue
    tmp2=[]
    for b in tmp:
        if (b>>i &1):
            tmp2.append(b)
    if len(tmp2)>=k:
        ans+=2**i
        tmp=tmp2
    else:
        pass
print(ans)

# Buggy version:
from itertools import accumulate
n, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))

btfl = []
for i in range(0, n):
    for j in range(i + 1, n + 1):
        btfl.append(a[j] - a[i])

# 解説AC
ans = 0
for i in range(50)[::-1]:
    num, cnt = ans + pow(2, i), 0
    for b in btfl:
        if num == num & b:
            cnt += 1
    print(num,cnt)
    if cnt >= k:
        ans = num
print(ans)


# Fixed version:
from itertools import accumulate

def main():
    n, k = map(int, input().split())
    a = [0] + list(accumulate(map(int, input().split())))

    btfl = []
    for i in range(0, n):
        for j in range(i + 1, n + 1):
            btfl.append(a[j] - a[i])

    # 解説AC
    ans = 0
    for i in range(50)[::-1]:
        num, cnt = ans + pow(2, i), 0
        for b in btfl:
            if num == num & b:
                cnt += 1
        if cnt >= k:
            ans = num
    print(ans)

if __name__ == '__main__':
    main()

# Buggy version:
import sys
import copy

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    s = []
    for i in range(N):
        tmp = A[0]
        s.append(tmp)
        for j in range(i + 1, N):
            tmp += A[j]
            s.append(tmp)

    s.sort(reverse=True)
    M = s[0]
    ans = 0
    n = M.bit_length()
    for i in range(n):
        tmp = []
        for v in s:
            if 1 << (n - i - 1) & v:
                tmp.append(v)
        if len(tmp) >= K:
            ans += 1 << (n - i - 1)
            s = copy.deepcopy(tmp)

    print(ans)


if __name__ == "__main__":
    main()


# Fixed version:
import sys
import copy

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    s = []
    for i in range(N):
        tmp = A[i]
        s.append(tmp)
        for j in range(i + 1, N):
            tmp += A[j]
            s.append(tmp)

    s.sort(reverse=True)
    M = s[0]
    ans = 0
    n = M.bit_length()
    for i in range(n):
        tmp = []
        for v in s:
            if 1 << (n - i - 1) & v:
                tmp.append(v)
        if len(tmp) >= K:
            ans += 1 << (n - i - 1)
            s = copy.deepcopy(tmp)

    print(ans)


if __name__ == "__main__":
    main()

# Buggy version:
n,k = map(int,input().split())
A = list(map(int,input().split()))
P = [0]+A
for i in range(1,n+1):
    P[i] += P[i-1]
temp = []
for i in range(n+1):
    for j in range(i+1, n+1):
        temp.append(P[j]-P[i])
print(temp)
ans = 0
for i in range(40, -1, -1):
    cur = ans+2**i
    cnt = 0
    for j in range(len(temp)):
        if temp[j]&cur == cur:
            cnt += 1
        if cnt >= k:
            break
    if cnt == k:
        ans += 2**i
print(ans)


# Fixed version:
n,k = map(int,input().split())
A = list(map(int,input().split()))
P = [0]+A
for i in range(1,n+1):
    P[i] += P[i-1]
temp = []
for i in range(n+1):
    for j in range(i+1, n+1):
        temp.append(P[j]-P[i])
ans = 0
for i in range(40, -1, -1):
    cur = ans+2**i
    cnt = 0
    for j in range(len(temp)):
        if temp[j]&cur == cur:
            cnt += 1
        if cnt >= k:
            break
    if cnt == k:
        ans += 2**i
print(ans)

# Buggy version:
n,k = map(int,input().split())
a = list(map(int,input().split()))
sal = [0] * (n*(n+1)//2)
l = 0
for i in range(n):
  for j in range(i,n):
    sal[l] = sum(a[i:j+1])
    l += 1
ans = 0
for i in range(40)[::-1]:
    cnt = 0
    temp = ans + 2**i
    for j in a:
        if temp&j == temp:
            cnt += 1
    if cnt >= k:
        ans = temp
print(ans)


# Fixed version:
n,k = map(int,input().split())
a = list(map(int,input().split()))
sal = [0] * (n*(n+1)//2)
l = 0
for i in range(n):
  for j in range(i,n):
    sal[l] = sum(a[i:j+1])
    l += 1
ans = 0
for i in range(41)[::-1]:
    cnt = 0
    temp = ans + 2**i
    for j in sal:
        if temp&j == temp:
            cnt += 1
    if cnt >= k:
        ans = temp
print(ans)

# Buggy version:
import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A_cum = A.cumsum()
beauties = []
for i, j in itertools.combinations(range(N+1), 2):
    beauties.append(A_cum[j] - A_cum[i])

beauties.sort(reverse=True)
j = 0
def check(x):
    return sum([x&y == x for y in beauties]) >= K

answer = 0
for i in range(40, -1, -1):
    if check(answer + 1 << i):
        answer += 1 << i

print(answer)
# 00


# Fixed version:
import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A_cum = A.cumsum()
beauties = []
for i, j in itertools.combinations(range(N+1), 2):
    beauties.append(A_cum[j] - A_cum[i])

beauties = np.array(beauties)
j = 0
def check(x):
    return np.sum(beauties&x == x) >= K

answer = 0
for i in range(40, -1, -1):
    if check(answer + (1 << i)):
        answer += 1 << i

print(answer)
# 00

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,0,-1):
  x=0
  s=2**i-1
  for j in range(l):
    if b[j]%s==0:
      b[j]//=s
      x+=1
  if x>=k:ans+=s
print(s)

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=0
  for j in range(i,n):
    x+=a[j]
    b.append(x)
ans=0
l=len(b)
for i in range(40,-1,-1):
  x=0
  s=2**i
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

# Buggy version:
n,k=map(int,input().split())
lists=list(map(int,input().split()))
GG=[]
for i in range(len(lists)+1):
    for j in range(i,len(lists)):
        
        G=sum(lists[i:j+1])
        GG.append(G)
        
GG=sorted(GG,reverse=True)      
maxi=format(GH[0],"b")
from collections import deque
d=deque()
e=deque()
for j in range(len(GG)):
    d.append(format(GG[j],"b").zfill(len(maxi)))
answer=0
index=0

while index!=len(maxi):
    counter=0
    for some in d:
        if some[index]=="1":
            counter+=1
            e.append(some)
    if counter>=k:
        answer+=2**(len(maxi)-1-index)
        d=e
        e=deque()
    elif counter<k:
        d=d
        e=deque()
        
    index+=1
    counter=0


print(answer)

# Fixed version:
n,k=map(int,input().split())
lists=list(map(int,input().split()))
GG=[]
sumlist=[0]
a=0
for i in range(len(lists)):
    a+=lists[i]
    sumlist.append(a) 
for i in range(len(sumlist)):
    for j in range(i+1,len(sumlist)):
        
        G=sumlist[j]-sumlist[i]
        GG.append(G)
        
GG=sorted(GG,reverse=True)      
maxi=format(GG[0],"b")
from collections import deque
d=deque()
e=deque()
for j in range(len(GG)):
    d.append(format(GG[j],"b").zfill(len(maxi)))
answer=0
index=0
 
while index!=len(maxi):
    counter=0
    for some in d:
        if some[index]=="1":
            counter+=1
            e.append(some)
    if counter>=k:
        answer+=2**(len(maxi)-1-index)
        d=e
        e=deque()
    elif counter<k:
        d=d
        e=deque()
        
    index+=1
    counter=0
print(answer)

# Buggy version:
#XorではなくAND
#上の桁優先、不可能なら無視
import bisect
n,k=map(int, input().split())
a_ = list(map(int, input().split()))

a = []

for i in range(n):
    a_sm = a_[i]
    a.append(a_sm)
    for j in range(i+1,n):
        a_sm+=a_[j]
        a.append(a_sm)

a.sort()
#print(a)
ans = 0
for j in range(41,-1,-1):##10**9を1000個足すので30では足りない
    x = 1<<j
    t = bisect.bisect_left(a,x)
    if t<=len(a)-k-1:###
        ans+=x
        a = a[t:]
        """
        for i in range(len(a)):
            a[i]&=(x-1)
        print(a)
        """
    for i in range(len(a)):
        a[i]&=(x-1)
        
    a.sort()
print(ans)
   


# Fixed version:
#XorではなくAND
#上の桁優先、不可能なら無視
import bisect
n,k=map(int, input().split())
a_ = list(map(int, input().split()))

a = []

for i in range(n):
    a_sm = a_[i]
    a.append(a_sm)
    for j in range(i+1,n):
        a_sm+=a_[j]
        a.append(a_sm)

a.sort()
#print(a)
ans = 0
for j in range(41,-1,-1):##10**9を1000個足すので30では足りない
    x = 1<<j
    t = bisect.bisect_left(a,x)
    if t<=len(a)-k:###
        ans+=x
        a = a[t:]
        """
        for i in range(len(a)):
            a[i]&=(x-1)
        print(a)
        """
    for i in range(len(a)):
        a[i]&=(x-1)
        
    a.sort()
print(ans)

# Buggy version:
n,k = map(int, input().split())
l = [0] + list(map(int, input().split()))
a = list()
for i in range(n):
  l[i+1] += l[i]
a = [l[j]-l[i] for j in range(i+1,n+1) for i in range(n)]
x = 0
for i in range(40,-1,-1):
  t = 2**i
  if sum(map(lambda y:(y&(t+x) == t+x),a)) >= k:
    x += t
print(x)


# Fixed version:
n,k = map(int, input().split())
l = [0] + list(map(int, input().split()))
a = list()
for i in range(n):
  l[i+1] += l[i]
a = [l[j]-l[i] for i in range(n) for j in range(i+1,n+1)]
x = 0
for i in range(40,-1,-1):
  t = 2**i 
  if sum(map(lambda y:((y&(t+x)) == t+x),a)) >= k:
    x += t
print(x)

# Buggy version:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)#[-k:]
ans=0
i=0
i2=1
while i2<c[-1]:
    ans+=i2 if sum([j&(ans+i2)>0 for j in c])>=k else 0
    #print(i2,sum([j>>i&1 for j in c]))
    i2*=2
    i+=1
    
print(ans)


# Fixed version:
from heapq import heappush, heappop
from collections import deque
import itertools
from itertools import permutations
import sys

import bisect
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
GYN=['Yes','trumpet']
mo=10**9+7
imp='IMPOSSIBLE'

n,k=MI()
a=LI()
A=[0]
for i in a:
    A+=[A[-1]+i]
b=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        b+=[A[j]-A[i]]
        
c=sorted(b)#[-k:]
ans=0
i=0
i2=2**40
while i2>0:
#    print(i2,sum([(j&(ans+i2))==(ans+i2) for j in c]))
    ans+=i2 if sum([(j&(ans+i2))==(ans+i2) for j in c])>=k else 0
    i2//=2
    i+=1
    
print(ans)#,A,c)
#print()

# Buggy version:
N, K =map(int, input().split())
a = list(map(int, input().split()))
cumsum = [0]
for i in range(N):
    cumsum.append( a[i] + cumsum[i] )
#print("{}".format(cumsum))

beauty = []
for l in range(N + 1):
    for r in range(l + 1, N + 1):
        beauty.append(cumsum[r] - cumsum[l])
beauty.sort()
#print("{}".format(beauty))

max = 0
for shift in range(4, 0, -1):
    mask = 1 << shift
    count = 0
#    print("{} {}".format(shift,beauty))
    for i in range(len(beauty)-1,-1,-1):
#        print("{} {}".format(i,beauty[i]))
        if (beauty[i] & mask) == 0:
            continue
        count+=1
    if count >= K:
#        print("{} {} {}".format(shift,max,mask))
        max |= mask;
#        print("{} {} {}".format(shift,max,mask))
        tmp = []
        for i in range(len(beauty) - 1, -1, -1):
            if ((beauty[i] & mask) == 0):
                continue
            tmp.append(beauty[i])
        beauty.clear()
        for i in range(len(tmp)):
            beauty.append(tmp[i])
print(max)


# Fixed version:
N, K =map(int, input().split())
a = list(map(int, input().split()))
cumsum = [0]
for i in range(N):
    cumsum.append( a[i] + cumsum[i] )
#print("{}".format(cumsum))

beauty = []
for l in range(N + 1):
    for r in range(l + 1, N + 1):
        beauty.append(cumsum[r] - cumsum[l])
beauty.sort()
#print("{}".format(beauty))

max = 0
for shift in range(60, -1, -1):
    mask = 1 << shift
    count = 0
#    print("{} {}".format(shift,beauty))
    for i in range(len(beauty)-1,-1,-1):
#        print("{} {}".format(i,beauty[i]))
        if (beauty[i] & mask) == 0:
            continue
        count+=1
    if count >= K:
#        print("{} {} {}".format(shift,max,mask))
        max |= mask;
#        print("{} {} {}".format(shift,max,mask))
        tmp = []
        for i in range(len(beauty) - 1, -1, -1):
            if ((beauty[i] & mask) == 0):
                continue
            tmp.append(beauty[i])
        beauty.clear()
        for i in range(len(tmp)):
            beauty.append(tmp[i])
print(max)

# Buggy version:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
B=[]
for i in range(1,N+1):
    for j in range(N-i+1):
        B.append(A[i+j]-A[j])
B.sort(reverse=True)
m=40
x=0
for t in range(m,0,-1):
    res=0
    for a in B:
        if ((x+1<<(t-1))&a)==(x+1<<(t-1)):
            res+=1
        if res>=K:
            x+=1<<(t-1)
            break
print(x)


# Fixed version:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
for i in range(N):
    A[i+1]+=A[i]
B=[]
for i in range(1,N+1):
    for j in range(N-i+1):
        B.append(A[i+j]-A[j])
B.sort(reverse=True)
m=40
x=0
for t in range(m,0,-1):
    res=0
    for a in B:
        if ((x+2**(t-1))&a)==(x+2**(t-1)):
            res+=1
        if res>=K:
            x+=2**(t-1)
            break
print(x)

# Buggy version:
N, K = map(int, input().split())
A = list(map(int, input().split()))


def countMask(a):
    ret = 0
    for x in cand:
        if (x & a) == a:
            ret += 1
    return ret


cand = []
for i in range(N):
    sum = 0
    for j in range(j, N):
        sum += A[j]
        cand.append(sum)

ans = 0

for i in range(40, -1, -1):
    if (countMask(ans | (1 << i)) >= K):
        ans |= 1 << i

print(ans)

# Fixed version:
N, K = map(int, input().split())
A = list(map(int, input().split()))


def countMask(a):
    ret = 0
    for x in cand:
        if (x & a) == a:
            ret += 1
    return ret


cand = []
for i in range(N):
    sum = 0
    for j in range(i, N):
        sum += A[j]
        cand.append(sum)

ans = 0

for i in range(40, -1, -1):
    if (countMask(ans | (1 << i)) >= K):
        ans |= 1 << i

print(ans)

# Buggy version:
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i+1,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

# Fixed version:
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

# Buggy version:
n,k=map(int,input().split())
 
d=list(map(int,input().split()))

ds = []

for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

o = []
ds.sort(reverse=True)

sum = 0
for i in range(32,-1,-1):
    count = 0
    o.clear()

    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        sum += 1 << i
        ds = o

print(sum)

# Fixed version:
n,k=map(int,input().split())
d=list(map(int,input().split()))

ds = []
 
for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)

ds.sort(reverse=True)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        ds = list(o)
  
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

# Buggy version:
n,k=map(int,input().split())
d=list(map(int,input().split()))

ds = []

for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)
        //print(str(sum) + " ",end='')
    //print()

ds.sort(reverse=True)

sum = 0
for i in range(40,-1,-1):
    count = 0
    o = []
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        sum += 1 << i
        ds = o

print(sum)

# Fixed version:
n,k=map(int,input().split())
d=list(map(int,input().split()))

ds = []

for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)
        #print(str(sum) + " ",end='')
    #print()

ds.sort(reverse=True)

sum = 0
for i in range(40,-1,-1):
    count = 0
    o = []
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        sum += 1 << i
        ds = o

print(sum)

# Buggy version:
a,b = map(int,input().split())

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

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0

for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (2 ** i) == (2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)


# Fixed version:
a,b = map(int,input().split())

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

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)

# Buggy version:
#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(sum(temp))
    if i==n:
        break
    i+=1

def check(num):
    for i in range(100):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = sum(ls_target[0])
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if ls & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

# Fixed version:
#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(sum(temp))
    if i==n:
        break
    i+=1

def check(num):
    for i in range(50):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = ls_target[0]
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if ls & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

# Buggy version:



def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:061b}".format(sum(As[i:j])))
    print("alls", len(alls))
    def find(i, alls):
        if i > 60:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))


# Fixed version:
def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:041b}".format(sum(As[i:j])))
    def find(i, alls):
        if i > 40:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))

# Buggy version:
import math

n, kk = tuple(map(int, input().split()))
sumnum = n * (n + 1) // 2
arr = tuple(map(int, input().split()))
sums = [0 for i in range(sumnum)]
hojo = [0 for i in range(n)]
point = 0
maxe = 0

for i, e in enumerate(arr):
    for k in range(i):
        hojo[k] += e
        sums[point] = hojo[k]
        point += 1
    hojo[i] = e
    sums[point] = hojo[i]
    point += 1

    if maxe < e:
        maxe = e

maxlog = 0
while maxe >= 1 << maxlog:
    maxlog += 1

res = 0

for i in range(maxlog, -1, -1):
    ya = [0 for i in range(len(sums))]
    dab = 0
    gaga = 1 << i
    for e in sums:
        if e & gaga:
            ya[dab] = e
            dab += 1

    if dab >= kk:
        res += gaga
        sums = ya[:dab]

print(res)


# Fixed version:
import math

n, kk = tuple(map(int, input().split()))
sumnum = n * (n + 1) // 2
arr = tuple(map(int, input().split()))
sums = [0 for i in range(sumnum)]
hojo = [0 for i in range(n)]
point = 0

for i, e in enumerate(arr):
    for k in range(i):
        hojo[k] += e
        sums[point] = hojo[k]
        point += 1
    hojo[i] = e
    sums[point] = hojo[i]
    point += 1

maxlog = 0
maxe = max(sums)
while maxe >= 2**maxlog:
    maxlog += 1
maxlog -= 1

res = 0

for i in range(maxlog, -1, -1):
    ya = [0 for i in range(len(sums))]
    dab = 0
    gaga = 1 << i
    for e in sums:
        if e & gaga:
            ya[dab] = e
            dab += 1

    if dab >= kk:
        res += gaga
        sums = ya[:dab]

print(res)

# Buggy version:
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = []
for i in range(N):
    B += [A[i]]
    for j in range(i+1,N):
        B += [B[-1] + A[j]]

ans = 0
for i in range(40, -1, -1):
    B_new = []
    for b in B:
        if b & 1 << i:
            B_new += [b]
    if len(B_new) >= K:
        ans += 1 << i
        B = [_ % 1 << i for _ in B_new]
    else:
        B = [_ % 1 << i for _ in B]
print(ans)

# Fixed version:
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = []
for i in range(N):
    B += [A[i]]
    for j in range(i+1,N):
        B += [B[-1] + A[j]]

ans = 0
for i in range(40, -1, -1):
    B_new = []
    for b in B:
        if b & 2 ** i:
            B_new += [b]
    if len(B_new) >= K:
        ans += 2 ** i
        B = [_ - 2 ** i for _ in B_new]
    else:
        B = [_ % 2 ** i for _ in B]
print(ans)

# Buggy version:
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))

a = np.array(a)

s = 0
e = 0

arr = []
for s in range(N):
    for e in range(s+1, N+1):
        arr.append(a[s:e])

max_len = len(bin(np.sum(a))[2:])

su = 0
b = [bin(np.sum(aa))[2:] for aa in arr]
b = ['0' * (max_len - len(bb)) + bb for bb in b]
while True:
    c = [bb for bb in b if bb[0] == '1']
    if len(c) >= K:
        su += 2 ** (len(c[0]) - 1)
        b = [cc[1:] for cc in c]
    else:
        b = [bb[1:] for bb in b]
    if len(b[0]) == 0:
        break
print(su)

# Fixed version:
import numpy as np
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))

a = np.array(a)

s = 0
e = 0

arr = []
aa = np.append(0,np.cumsum(a))
for s in range(len(aa)):
    for e in range(s+1, len(aa)):
        arr.append(aa[e] - aa[s])

max_len = len(bin(np.sum(a))[2:])

su = 0
b = [bin(aa)[2:] for aa in arr]
b = ['0' * (max_len - len(bb)) + bb for bb in b]
while True:
    c = [bb for bb in b if bb[0] == '1']
    if len(c) >= K:
        su += 2 ** (len(c[0]) - 1)
        b = [cc[1:] for cc in c]
    else:
        b = [bb[1:] for bb in b]
    if len(b[0]) == 0:
        break
print(su)

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0,a[0]]
for i in range(1,n):
    x.append(x[-1]+a[i])
y=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        y.append(x[j]-x[i])
y.sort()
y=y[::-1]
m=len(bin(y[0]))
y=["0"*(m-len(bin(y[i])))+bin(y[i])[2::] for i in range(len(y))]
res=["0" for _ in range(m-2)]
for x in range(m-2):
    t=0
    z=[]
    for i in range(len(y)):
        if y[i][x]=="1":
            t+=1
            z.append(y[i])
    if t>=k:
        res[x]="1"
        y=z[::]
print(res)

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0,a[0]]
for i in range(1,n):
    x.append(x[-1]+a[i])
y=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        y.append(x[j]-x[i])
y.sort()
y=y[::-1]
m=len(bin(y[0]))
y=["0"*(m-len(bin(y[i])))+bin(y[i])[2::] for i in range(len(y))]
res=["0" for _ in range(m-2)]
for x in range(m-2):
    t=0
    z=[]
    for i in range(len(y)):
        if y[i][x]=="1":
            t+=1
            z.append(y[i])
    if t>=k:
        res[x]="1"
        y=z[::]
print(int("".join(res),2))