CodeEff/ECCO huggingface dataset:
# Original solution
#横にn個入力
n, k = list(map(int, input().split()))
a = input().split()
a = [int(m) for m in a]
nli = []
b = 0
for i in range(n):
    for j in range(i, n):
        b += a[j]
        nli.append(b)
    b = 0
nli.sort(reverse=True)
m = 40
x = 0

cnt = 0
candili = []
for i in range(m - 1, 0, -1):
    if x == 0:
        for j in range(len(nli)):
            if nli[j] & (x + 2 ** i) == x + 2 ** i:
                candili.append(nli[j])
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
    else:
        for j in candili:
            if j & (x + 2 ** i) == x + 2 ** i:
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
print(x)

# Optimized solution
#横にn個入力
n, k = list(map(int, input().split()))
a = input().split()
a = [int(m) for m in a]
nli = []
b = 0
for i in range(n):
    for j in range(i, n):
        b += a[j]
        nli.append(b)
    b = 0
nli.sort(reverse=True)
m = 41
x = 0

cnt = 0
candili = []
for i in range(m - 1, -1, -1):
    if x == 0:
        for j in range(len(nli)):
            if nli[j] & (x + 2 ** i) == x + 2 ** i:
                candili.append(nli[j])
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
            candili = []
    else:
        for j in candili:
            if j & (x + 2 ** i) == x + 2 ** i:
                cnt += 1
        if cnt >= k:
            x += 2 ** i
            cnt = 0
        else:
            cnt = 0
print(x)
# Original solution
import itertools as tool

N, K = list(map(int, input().split()))
a = [int(x) for x in input().split()]

beautifuls = []
for i in range(0, len(a)):
    for j in range(i+1, len(a)+1):
        beautiful = sum(a[i:j])
        beautifuls.append(beautiful)

beau_K = list(tool.combinations(beautifuls, K))
ands = []
for combi in beau_K:
    for i in range(K):
        if i == 0:
            tmp = combi[0]
        else:
            tmp = eval(str(bin(tmp & combi[i])))
    ands.append(eval(str(tmp)))
print((max(ands)))


# Optimized solution

N, K = list(map(int, input().split()))
a = [int(x) for x in input().split()]

beautifuls = []
for i in range(0, len(a)):
    for j in range(i+1, len(a)+1):
        beautiful = sum(a[i:j])
        beautifuls.append(beautiful)

x_ = 0
t = 1
count = 0
while 1:
    for i in range(len(beautifuls)):
        if eval(str(bin((x_ + 2**(t-1)) & beautifuls[i]))) == x_+ 2**(t-1):
            count += 1
            if count == K:
                x_ += 2**(t-1)
                t = 0
                break
    count = 0
    t += 1
    if t > 40:
        break

print(x_)
# Original solution
from itertools import accumulate

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

accAs = [0] + list(accumulate(As))

Bs = []
for L in range(N):
    for R in range(L, N):
        Bs.append(accAs[R + 1] - accAs[L])

ans = 0
for d in reversed(list(range(50))):
    num = sum([(B >> d) & 1 for B in Bs])
    if num >= K:
        ans += 1 << d
        Bs = [B if (B >> d) & 1 else 0 for B in Bs]

print(ans)


# Optimized solution
from itertools import accumulate

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

accAs = [0] + list(accumulate(As))

Bs = []
for L in range(N):
    for R in range(L, N):
        Bs.append(accAs[R + 1] - accAs[L])

ans = 0
for d in reversed(list(range(40))):
    num = sum([(B >> d) & 1 for B in Bs])
    if num >= K:
        ans += 1 << d
        Bs = [B for B in Bs if (B >> d) & 1]

print(ans)
# Original solution
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)


# Optimized solution
ma = lambda :list(map(int,input().split()))
lma = lambda :list(map(int,input().split()))

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(tmp)>=k:
        ans+=2**i
        bu=tmp
    else:
        pass
print(ans)
# Original solution
def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)

s = [bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)]

ans = [0] * 40

for i in range(40):
    t = [j for j in s if j[i] == '1']
    if len(t) >= K:
        ans[i] = 1
        s = t

print((sum([ans[i] * 2**(39-i) for i in range(40)])))

# Optimized solution
def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

N, K = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)

s = [bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)]

ans = 0

for i in range(40):
    t = [j for j in s if j[i] == '1']
    if len(t) >= K:
        ans += 2**(39-i)
        s = t

print(ans)
# Original solution
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    subs = []
    for left in range(n):
        for right in range(left + 1, n + 1):
            subs.append(R[right] - R[left])

    res = 0
    for mask in reversed(list(range(40))):
        if len(subs) == 0:
            break
        tmp = []
        for i in range(len(subs)):
            if subs[i] & (1 << mask):
                tmp.append(subs[i])
        if len(tmp) >= k:
            res += 1 << mask
            subs = tmp
    print(res)


if __name__ == '__main__':
    resolve()


# Optimized solution
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    subs = []
    for left in range(n + 1):
        for right in range(left + 1, n + 1):
            num = R[right] - R[left]
            subs.append(num)

    for i in reversed(list(range(41))):
        tmp = []
        for num in subs:
            if num & (1 << i):
                tmp.append(num)
        if len(tmp) >= k:
            subs = tmp

    res = subs[0]
    for num in subs:
        res &= num
    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
n, k = list(map(int, input().split()))
As = list(map(int, input().split()))

from itertools import accumulate
acc = [0]+list(accumulate(As))
dp = [0] * 50
mx = 0
sums = []
for i in range(n+1):
    for j in range(i+1,n+1):
        s = acc[j]-acc[i]
        sums.append(s)

# 最大の桁数
for d in range(50):
    if max(sums) & (1<<d):
        mx = max(mx, d)
        dp[d] += 1
mx = 0
for i in range(50):
    if dp[i] >= k:
        mx = max(mx,i)

ans = 0
now = 0
for d in range(50,-1,-1):
    cnt = 0
    for s in sums:
        if s & (now+(1<<d)) == now+(1<<d):
            cnt += 1
    # print(d,cnt)
    if cnt >= k:
        now += 1<<d
print(now)

# Optimized solution
n, k = list(map(int, input().split()))
As = list(map(int, input().split()))

from itertools import accumulate
acc = [0]+list(accumulate(As))
dp = [0] * 50
mx = 0
sums = []
for i in range(n+1):
    for j in range(i+1,n+1):
        s = acc[j]-acc[i]
        sums.append(s)

# 最大の桁数
for d in range(50):
    if max(sums) & (1<<d):
        mx = max(mx, d)
        dp[d] += 1
mx = 0
for i in range(50):
    if dp[i] >= k:
        mx = max(mx,i)

# 計算
ans = 0
now = 0
for d in range(50,-1,-1):
    cnt = 0
    for s in sums:
        if s & (now+(1<<d)) == now+(1<<d):
            cnt += 1
    # print(d,cnt)
    if cnt >= k:
        now += 1<<d
print(now)
# Original solution
def b_len(v):
    return len(bin(v)[2:])


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

cs = [0]
for aa in a:
    cs.append(cs[-1] + aa)

ps = []
for i in range(1, n + 1):
    for j in range(i):
        ps.append(cs[i] - cs[j])

ps = sorted(ps, reverse=True)

pw = b_len(ps[k - 1])
MOD = 2 ** pw

nps = {i:set() for i in range(pw)}
for i in range(len(ps)):
    t = ps[i] % MOD
    for j in range(pw):
        if 1 << j & t:
            nps[j].add(i)

ans = 0
buf = set(range(len(ps)))
for j in range(pw)[::-1]:
    if len(nps[j]) >= k:
        x = buf & nps[j]
        if len(x) >= k:
            buf = x
            ans += 2 ** j

print(ans)

# Optimized solution
from math import log, ceil

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

A_MAX = 10 ** 9
MAX_BIT_LENGTH = ceil(log(A_MAX * n, 2))

cs = [0]
t = 0
for aa in a:
    t += aa
    cs.append(t)

ps = []
for r in range(1, n + 1):
    for l in range(r):
        ps.append(cs[r] - cs[l])

ans = 0
for b in range(MAX_BIT_LENGTH)[::-1]:
    cnt = 0
    t = ans + (1 << b)
    for p in ps:
        if p & t == t:
            cnt += 1
            if cnt == k:
                ans = t
                break

print(ans)
# Original solution
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

s = 0
ma = 0
for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])
    ma = max(ma, max(C))

IDX = 0
while ((1 << IDX) < ma):
    IDX += 1


def filterList(list, i):
    retList = []
    for l in list:
        if l & (1 << i):
            retList.append(l)
    return retList

D = C
for i in range(IDX,-1,-1):
    newD = filterList(D,i)
    if len(newD) < K:
        break
    else:
        D = newD


EE = list(itertools.combinations(D, K))
EE = list(set(EE))

ret = 0
for E in EE:
    r = E[0]
    for e in E:
        r = r & e
    ret = max(ret, r)


print(ret)

sys.exit(0)


# Optimized solution
import sys

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])

D = C
ans = 0
for i in range(40,-1,-1):
    yes = []
    no = []
    for l in D:
        if l & (1 << i):
            yes.append(l)
        else:
            no.append(l)

    if len(yes) >= K:
        ans += 1 << i
        D = yes

print(ans)

sys.exit(0)
# Original solution
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        S.add(sum(b))

S = sorted(list(S))

ans = 0
for i in range(40, -1, -1):
    A = [s & (1 << i) for s in S]
    newS = list(compress(S, A))
    if len(newS) >= K:
        ans += (1 << i)
        S = newS

print(ans)


# Optimized solution
import sys
import collections
from collections import Counter
# from collections import deque
# from collections import defaultdict
import itertools
# from itertools import accumulate
# from itertools import permutations
# from itertools import combinations
# from itertools import takewhile
from itertools import compress
# import functools
# from functools import reduce
import math
# from math import gcd
# from math import inf
# from math import ceil
# from math import floor
# from math import log10
# from math import log2
# from math import log
from math import factorial

# import re

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

S = set()
for i in range(N):
    for j in range(i, N):
        b = A[i:j + 1]
        S.add(sum(b))

S = list(S)

ans = 0
for i in range(40, -1, -1):
    A = [s & (1 << i) for s in S]
    newS = list(compress(S, A))
    if len(newS) >= K:
        ans += (1 << i)
        S = newS

print(ans)
# Original solution
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)

# Optimized solution
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()
# Original solution
import copy
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
ans = 0
for d in range(41,-1,-1):
    c = 0
    for e in T:
        if (ans+2**d)&e == ans+2**d:
            c += 1
    if c >= K:
        ans += 2**d
print(ans)


# Optimized solution
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))
S = [0]*N
S[0] = a[0]
for k in range(1,N):
    S[k] = S[k-1] + a[k]
S = [0] + S
T = []
for k in range(N):
    for l in range(k+1,N+1):
        T.append(S[l]-S[k])
ans = 0
for d in range(41,-1,-1):
    c = 0
    for e in T:
        if (ans+2**d)&e == ans+2**d:
            c += 1
    if c >= K:
        ans += 2**d
print(ans)
# Original solution
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,k = li()
a = list(li())

acum = list(accumulate([0]+a))

cand = []
for i in range(n+1):
    for j in range(i+1,n+1):
        cand.append(acum[j] - acum[i])

ans = 0

for mask in range(40, -1, -1):
    satis = sum([bool(ci&(1<<mask)) for ci in cand])

    if satis >= k:
        ans += (1<<mask)
        nex = [ci for ci in cand if ci & (1<<mask)]
        cand = nex
        

print(ans)

# Optimized solution
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()
a = list(li())

cum = [0]
for ai in a:
    cum.append(cum[-1] + ai)

pool = []
for i in range(n+1):
    for j in range(i+1, n+1):
        pool.append(cum[j] - cum[i])

MAX_BIT = 41
ans = 0
for bit in range(MAX_BIT, -1, -1):
    new_pool = []
    for poli in pool:
        if poli & (1<<bit):
            new_pool.append(poli)

    if len(new_pool) >= k:
        ans += (1<<bit)
        pool = new_pool

print(ans)
# Original solution
import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
# def input():
#     return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
rlst=ruiseki(a)
# print(rlst)
lst=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        # print(i,j)
        lst.append(rlst[j]-rlst[i])
# print(lst)
tmp=math.log(rlst[-1],2)
now=int(tmp)

while now>=0:
    anslst=[]
    for i in range(len(lst)):
        if 1&(lst[i]>>now)==1:
            anslst.append(lst[i])
    if len(anslst)>=k:
        lst=anslst
    now-=1
# print(lst)
ans=lst[0]
for i in range(k):
    ans=ans&lst[i]
print(ans)

# Optimized solution
import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
rlst=ruiseki(a)
# print(rlst)
lst=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        # print(i,j)
        lst.append(rlst[j]-rlst[i])
# print(lst)
tmp=math.log(rlst[-1],2)
now=int(tmp)

while now>=0:
    anslst=[]
    for i in range(len(lst)):
        if 1&(lst[i]>>now)==1:
            anslst.append(lst[i])
    if len(anslst)>=k:
        lst=anslst
    now-=1
# print(lst)
ans=lst[0]
for i in range(k):
    ans=ans&lst[i]
print(ans)
# Original solution
from itertools import accumulate as ac
from functools import reduce

n,k=list(map(int,input().split()))
*ac,=ac([0]+list(map(int,input().split())))

l=[ac[j]-ac[i] for i in range(n+1) for j in range(i+1,n+1)]
count_bits=lambda n:sum([x&n==n for x in l])

ans=0
for i in range(41)[::-1]:
    if count_bits(ans|1<<i)>=k:
        ans|=1<<i

print(ans)

# Optimized solution
from itertools import accumulate as ac

n,k=list(map(int,input().split()))
*a,=ac([0]+list(map(int,input().split())))

l=[a[j]-a[i] for i in range(n+1) for j in range(i+1,n+1)]
f=lambda n:sum([x&n==n for x in l])

ans=0
for i in range(41)[::-1]:
    if f(ans|1<<i)>=k:
        ans|=1<<i

print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(64)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = "{:b}".format(acc[j+1] - acc[i])
        s = s.zfill(64)
        for num, bit in enumerate(s):
            if bit == "1":
                stand_bit[num].add(acc[j+1] - acc[i])
for i in range(64):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)



# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(64)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = acc[j+1] - acc[i]
        index = 63
        while s :
            if s & 1:
                stand_bit[index].add(acc[j+1] - acc[i])
            s = s >> 1
            index -= 1
for i in range(64):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(64)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = acc[j+1] - acc[i]
        index = 63
        while s :
            if s & 1:
                stand_bit[index].add(acc[j+1] - acc[i])
            s = s >> 1
            index -= 1
for i in range(64):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)



# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = acc[j+1] - acc[i]
        index = 41
        while s :
            if s & 1:
                stand_bit[index].add(acc[j+1] - acc[i])
            s = s >> 1
            index -= 1
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
acc[0] = 0
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        set_ans.add(acc[j+1] - acc[i])
        s = acc[j+1] - acc[i]
        index = 41
        while s:
            if s & 1:
                stand_bit[index].add(acc[j+1] - acc[i])
            s = s >> 1
            index -= 1
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
stand_bit = [set() for i in range(42)]
acc = [0 for i in range(n+1)]
for i in range(1, n+1):
    acc[i] += a[i-1] + acc[i-1]
set_ans = set()
for i in range(n):
    for j in range(i, n):
        tmp = acc[j+1] - acc[i]
        set_ans.add(tmp)
        s = tmp
        index = 41
        while s:
            if s & 1:
                stand_bit[index].add(tmp)
            s = s >> 1
            index -= 1
for i in range(42):
    if len(set_ans & stand_bit[i]) >= k:
        set_ans &= stand_bit[i]
ans_list = list(set_ans)
ans = ans_list[0]
for i in ans_list:
    ans &= i
print(ans)