CodeEff/ECCO huggingface dataset:
# Original solution
import sys

coins = [1,5,10,50,100,500]

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    c = [ i for i in range(n+1) ]
    for i in range(len(coins)):
        coin = coins[i]
        if coin <= n:
            c[coin] = 1
            coins.append(coin)

    for coin in coins:
        for p in range(coin+1, n+1):
            minc = c[p]
            if minc == 1:
                continue
            c[p] = c[p-coin]+1 if minc > c[p-coin] + 1 else minc

    print((c[n]))

# Optimized solution
import sys

coins = [500,100,50,10,5,1]

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    cnt = 0

    while n != 0:
        for i in range(len(coins)):
            if n >= coins[i]:
                n = n-coins[i]
                break
        cnt += 1

    print(cnt)
# Original solution
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

accum = [0] * N
for i in range(N):
    if i == 0:
        accum[i] = A[i]
    else:
        accum[i] = accum[i-1] + A[i]



B = []
for l in range(N):
    for r in range(l, N):
        if l == 0:
            B.append(accum[r])
        else:
            B.append(accum[r] - accum[l-1])




ans = 0
for i in range(50, -1, -1):
    
    cnt = 0
    nxt_B = []
    for b in B:
        if b & (1 << i):
            cnt += 1
            nxt_B.append(b)

    if cnt >= K:
        ans += 2**i
        B = nxt_B

print(ans)

# Optimized solution



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

accum = [0] * N
accum[0] = A[0]
for i in  range(1,N):
    accum[i] = accum[i-1] + A[i]

B = []
for l in range(N):
    for r in range(l,N):
        if l == 0:
            B.append(accum[r])
        else:
            B.append(accum[r] - accum[l-1])


ans = 0
for i in range(45,-1,-1):
    used = []
    cnt = 0
    for b in B:
        if b & (1 << i):
            cnt += 1
            used.append(b)

    if cnt >= K:
        ans += pow(2,i)
        B = used


print(ans)
# Original solution
import itertools

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []

for i in range(N):
    temp = 0
    for n in a[i:]:
        temp += n
        beautiful_num.append("{:040b}".format(temp))

ma_b_cnt = 0
target_set = None

for i in range(40):
    if target_set is None:
        for b in beautiful_num:
            if b[i] == "1":
                ma_b_cnt += 1
        if ma_b_cnt < K:
            ma_b_cnt = 0
        else:
            target_set = set([b for b in beautiful_num if b[i] == "1"])
    else:
        count = 0
        for b in target_set:
            if b[i] == 0:
                count += 1
        if len(target_set) - count >= K:
            for b in target_set:
                if b[i] == 0:
                    target_set.remove(b)
        else:
            break

result = 0
for comb in itertools.combinations(target_set, K):
    temp = bin(int(comb[0], 2))
    for b in comb:
        temp = bin(int(b, 2) & int(temp, 2))
    temp = int(temp, 2)
    if temp > result:
        result = temp

print(result)

# Optimized solution
import itertools

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []

for i in range(N):
    temp = 0
    for n in a[i:]:
        temp += n
        beautiful_num.append("{:040b}".format(temp))

ma_b_cnt = 0
target_set = None

result = 0
for i in range(40):
        for b in beautiful_num:
            if b[i] == "1":
                ma_b_cnt += 1
        if ma_b_cnt >= K:
            result += 2**(40-i-1)
            beautiful_num = [b for b in beautiful_num if b[i] == "1"]
        ma_b_cnt = 0

print(result)
# Original solution
import itertools

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []

for i in range(N):
    temp = 0
    for n in a[i:]:
        temp += n
        beautiful_num.append("{:040b}".format(temp))

ma_b_cnt = 0
target_set = None

result = 0
for i in range(40):
        for b in beautiful_num:
            if b[i] == "1":
                ma_b_cnt += 1
        if ma_b_cnt >= K:
            result += 2**(40-i-1)
            beautiful_num = [b for b in beautiful_num if b[i] == "1"]
        ma_b_cnt = 0

print(result)

# Optimized solution
import itertools

N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
beautiful_num = []

for i in range(N):
    temp = 0
    for n in a[i:]:
        temp += n
        beautiful_num.append(temp)

ma_b_cnt = 0
target_set = None

result = 0
for i in range(40, -1, -1):
        for b in beautiful_num:
            if b & 1 << i != 0:
                ma_b_cnt += 1
        if ma_b_cnt >= K:
            result += 2**i
            beautiful_num = [b for b in beautiful_num if b & 1 << i != 0]
        ma_b_cnt = 0

print(result)
# Original solution
n,k=list(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)

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)

# Optimized solution
n,k=list(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)
# Original solution
from itertools import accumulate

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

C = [0] + list(accumulate(A))
S = []

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

for i in range(64)[::-1]:
    tmp = []
    for s in S:
        if (s >> i) & 1:
            tmp.append(s)

    if len(tmp) >= K:
        S = tmp[:]

res = 2**64 - 1

for i in range(K):
    res &= S[i]

print(res)

# Optimized solution
from itertools import accumulate

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

C = [0] + list(accumulate(A))
S = []

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

for i in range(64)[::-1]:
    tmp = []
    for s in S:
        if (s >> i) & 1:
            tmp.append(s)

    if len(tmp) >= K:
        S = tmp

res = 2**64 - 1

for i in range(K):
    res &= S[i]

print(res)
# Original solution
from collections import Counter


def check(ans, s):
    ret = 0
    for k, v in list(Sumdic.items()):
        if ans & k != ans:
            continue
        ret += v
        if ret >= s:
            return True
    return False


n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = [0]
for i in range(len(A)):
    sumA.append(sumA[i] + A[i])

sumdic = [0] * (n * (n + 1) // 2)
kk = 0
for i in range(len(A)):
    # print(kk, sumdic)
    for j in range(i + 1, len(A) + 1):
        tmp = sumA[j] - sumA[i]
        sumdic[kk + j - 1 - i] = tmp
        # print(i, j)
    kk += n - i

# print(A)
# print(Counter(sumdic))
Sumdic = Counter(sumdic)

for i in reversed(list(range(len(format(sumA[-1], "b"))))):
    # print(i)
    if check(2 ** i, k) is True:
        ans = 2 ** i
        tmp = i
        break
else:
    print((0))
    exit()

tmp -= 1
while(tmp != -1):
    if check(ans + 2 ** tmp, k) is True:
        ans += 2 ** tmp
    tmp -= 1
print(ans)

# Optimized solution
def check(ans, s):
    ret = 0
    for k in sumdic:
        if ans & k != ans:
            continue
        ret += 1
        if ret >= s:
            return True
    return False


n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = [0]
for i in range(len(A)):
    sumA.append(sumA[i] + A[i])

sumdic = [0] * (n * (n + 1) // 2)
kk = 0
for i in range(len(A)):
    # print(kk, sumdic)
    for j in range(i + 1, len(A) + 1):
        tmp = sumA[j] - sumA[i]
        sumdic[kk + j - 1 - i] = tmp
        # print(i, j)
    kk += n - i

# print(A)
# print(Counter(sumdic))
# Sumdic = Counter(sumdic)

for i in reversed(list(range(len(format(sumA[-1], "b"))))):
    # print(i)
    if check(2 ** i, k) is True:
        ans = 2 ** i
        tmp = i
        break
else:
    print((0))
    exit()

tmp -= 1
while(tmp != -1):
    if check(ans + 2 ** tmp, k) is True:
        ans += 2 ** tmp
    tmp -= 1
print(ans)
# Original solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = list(map(int, input().split()))
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = []
for i in range(n+1):
    for j in range(i,n+1):
        s.append(list(format(a[j]-a[i], '050b')))

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)

# Optimized solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import itertools

n, k = list(map(int, input().split()))
a = list(itertools.accumulate(list(map(int, input().split()))))
a = [0] + a
s = [None] * (n*(n+1)//2)
cnt = 0
for i in range(n+1):
    for j in range(i+1,n+1):
        s[cnt] = format(a[j]-a[i], '050b')
        cnt += 1

ret = 0
sel = set(range(n*(n+1)//2))
for i in range(50):
    nxt = set([])
    for j in sel:
        if s[j][i] == '1':
            nxt.add(j)
    if len(nxt)>=k:
        sel = nxt
        ret += 2**(49-i)
print(ret)
# Original solution
import copy
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

max_num = max(score)
i = 0
while(True):
    if(2**(i+1)>max_num):
        break
    else:
        i+=1

ans = 0
for j in range(i,-1,-1):
    if len(score)<K:
        break
    count = 0
    score_a = []
    score_b = []
    for k in range(len(score)):
        if score[k] >= 2**j:
            count += 1
            score[k] -= 2**j
            score_a.append(score[k])
        score_b.append(score[k])
    if count >= K:
        ans += 2**j
        score = copy.deepcopy(score_a)
    else:
        score = copy.deepcopy(score_b)

print(ans)


# Optimized solution
import copy
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

ans = 0
for i in range(40,-1,-1):
    count = 0
    score_a = []
    for j in score:
        if (j & (1<<i)):
            count += 1
            score_a.append(j)
    if count >= K:
        ans += (1<<i)
        score = copy.deepcopy(score_a)

print(ans)
# Original solution
import copy
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

ans = 0
for i in range(40,-1,-1):
    count = 0
    score_a = []
    for j in score:
        if (j & (1<<i)):
            count += 1
            score_a.append(j)
    if count >= K:
        ans += (1<<i)
        score = copy.deepcopy(score_a)

print(ans)


# Optimized solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

A_sum = [0]
for a in A:
    A_sum.append(A_sum[-1]+a)

score = []
for r in range(1,N+1):
    for l in range(0,r):
        score.append(A_sum[r]-A_sum[l])

ans = 0
for i in range(40,-1,-1):
    count = 0
    score_a = []
    for j in score:
        if (j & (1<<i)):
            count += 1
            score_a.append(j)
    if count >= K:
        ans += (1<<i)
        score = [i for i in score_a]

print(ans)
# Original solution
from math import log2
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [[a[i]] for i in range(n)]
c = list(a)

for i in range(n-1):
    for j in range(i+1, n):
        b[i].append(a[j]+b[i][-1])
        c.append(b[i][-1])

m = 40 #ceil(log2((10**9)*1000))=40よりbit幅を40としておけば十分
ans = 0
for i in range(m, 0, -1):
    count = 0
    for p in c:
        if (ans + 2**(i-1)) & p == ans + 2**(i-1):
            count += 1
            if count == k:
                ans += 2**(i-1)
                break
print(ans)


# Optimized solution
from math import log2
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [[a[i]] for i in range(n)]
c = list(a)

for i in range(n-1):
    for j in range(i+1, n):
        b[i].append(a[j]+b[i][-1])
        c.append(b[i][-1])

m = 40 #ceil(log2((10**9)*1000))=40よりbit幅を40としておけば十分
ans = 0
for i in range(m, -1, -1):
    log = 2**i
    tmp = [x for x in c if x&log==log]
    if len(tmp) >= k:
        ans += log
        c = tmp
print(ans)
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=set()
for i in range(n):
     for j in range(i,n):
          s.add(sum(a[i:j+1]))
s=list(s)
x=0
for i in range(40):
     x_=x+2**(39-i)
     cnt=0
     for a in s:
          if x_&a==x_:
               cnt+=1
     if cnt>=k:
          x=x_
print(x)

# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=set()
for i in range(n):
     su=0
     for j in range(i,n):
          su+=a[j]
          s.add(su)
s=list(s)
x=0
for i in range(40):
     x_=x+2**(39-i)
     cnt=0
     for a in s:
          if x_&a==x_:
               cnt+=1
     if cnt>=k:
          x=x_
print(x)
# Original solution
def count(value, P):
    cnt = 0
    for p in P:
        if p & value == value:
            cnt += 1
    return cnt


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    P = []
    for i in range(N):
        for j in range(i+1, N+1):
            P.append(sum(A[i:j]))
    retval = 0
    for idx in range(40, -1, -1):
        tmp = retval + 2**idx
        if count(tmp, P) >= K:
            retval = tmp
    print(retval)


if __name__ == "__main__":
    main()


# Optimized solution
def count(value, P):
    cnt = 0
    for p in P:
        if p & value == value:
            cnt += 1
    return cnt


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    P = []
    for i in range(N):
        s = 0
        for j in range(i, N):
            s += A[j]
            P.append(s)
    retval = 0
    for idx in range(40, -1, -1):
        tmp = retval + 2**idx
        if count(tmp, P) >= K:
            retval = tmp
    print(retval)


if __name__ == "__main__":
    main()
# Original solution
# def to_2(num):
#     ret = []
#     while (num != 0):
#         if num % 2 == 1:
#             ret.append(True)
#         else:
#             ret.append(False)
#         num = num // 2
#     return np.array(ret)

# def()

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

# 全探索
from itertools import combinations
A_2 = [bin(a) for a in A]

kouho = [sum(A[idx:(idx2+1)]) for idx, idx2 in combinations(list(range(0, N)), 2)]


ma = 0
for A_sub in combinations(kouho, K):
    bina = A_sub[0]
    # print(bina)
    for i in range(1, K):
        bina = bina & A_sub[i]
    if bina > ma:
        ma = bina

print(ma)

# Optimized solution
# https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b
# 解説見てしまった
# N≤1000の性質をうまく使う必要はない。O(N^2)で全部書き出せばいい。完全に引っ掛け。
# 答えの仮定、bitごとに見る、上位桁からのgreedyらへんがキーワード

from itertools import combinations
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [sum(A[s:t]) for s, t in combinations(list(range(N + 1)), 2)]

l = max(B).bit_length()  # 何桁扱えば十分か？
x = 0  # 初期値
for i in range(l, -1, -1):  # 上位桁からgreedyに決定
    # 候補のうち i bit目=1がK個以上あれば答えに計上できる
    x_tmp = x + (1 << i)
    if sum((x_tmp & b) == x_tmp for b in B) >= K:  # 確定した桁+i桁を1としたときに答えになり得るか？
        x = x_tmp
print(x)
# Original solution
import itertools
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
c1 = list(itertools.combinations(list(range(n)),2))
s = a
for i in c1:
    s.append(b[i[1]]-b[i[0]]+a[i[0]])
c2 = list(itertools.combinations(list(range(len(s))),k))
max=0
for i in c2:
    t = s[i[0]]
    for j in i:
        t = t&s[j]
    if max < t:
        max = t
print(max)


# Optimized solution
import itertools
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
c = list(itertools.combinations(list(range(n)),2))
s = a
for i in c:
    s.append(b[i[1]]-b[i[0]]+a[i[0]])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    for i in range(len(s)):
        if s[i] >= d:
            s[i] -= d
        else:
            s.sort(reverse=True)
            break
    d //= 2
print(t)
# Original solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
s = b
for i in range(n-1):
    for j in range(i,n-1):
        s.append(b[j+1]-b[i])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    for i in range(len(s)):
        if s[i] >= d:
            s[i] -= d
        else:
            s.sort(reverse=True)
            break
    d //= 2
print(t)

# Optimized solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
s = b
for i in range(n-1):
    for j in range(i,n-1):
        s.append(b[j+1]-b[i])
s.sort(reverse=True)
l = len(bin(s[0]))-2
d = 1<<l-1
t = 0
while d>0:
    s1 = []
    if s[k-1] >= d:
        t += d
        for i in s:
            if i >= d:
                s1.append(i)
            else:
                s=s1
                break
    for i in range(len(s)):
        if s[i] >= d:
            s[i] -= d
        else:
            s.sort(reverse=True)
            break
    d = d>>1
print(t)
# Original solution
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))

sum_list=[]
for i in range(N):
  s=0
  for j in range(i,N):
    s+=alist[j]
    sum_list.append(s)
    
sum_list.sort(reverse=True)
#print(sum_list)

answer=0
for i in reversed(list(range(41))):
  x=2**i
  cnt=0
  for s in sum_list:
    if (answer+x)&s==answer+x:
      cnt+=1
      if cnt>=K:
        answer+=x
        break
  
print(answer)

# Optimized solution
N,K=list(map(int,input().split()))
alist=list(map(int,input().split()))

sum_list=[]
for i in range(N):
  s=0
  for j in range(i,N):
    s+=alist[j]
    sum_list.append(s)
    
sum_list.sort(reverse=True)
#print(sum_list)

answer=0
for i in reversed(list(range(41))):
  x=2**i
  cnt=0
  for s in sum_list:
    if answer+x>s:
      break
    elif (answer+x)&s==answer+x:
      cnt+=1
      if cnt>=K:
        answer+=x
        break
  
print(answer)
# Original solution
from itertools import accumulate, combinations

n, k = list(map(int, input().split()))
a = [0] + list(accumulate(list(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])

ans = 0
for l in combinations(btfl, k):
    cnt = l[0]
    for i in l:
        cnt &= i
    ans = max(ans, cnt)
print(ans)


# Optimized solution
from itertools import accumulate
n, k = list(map(int, input().split()))
a = [0] + list(accumulate(list(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)
# Original solution
from itertools import accumulate

def main():
    n, k = list(map(int, input().split()))
    a = [0] + list(accumulate(list(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()


# Optimized solution
from itertools import accumulate
n, k = list(map(int, input().split()))
a = [0] + list(accumulate(list(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)
# Original solution
n,k=list(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
  for j in range(l):
    if b[j]&(ans+s)==ans+s:x+=1
  if x>=k:ans+=s
print(ans)

# Optimized solution
n,k=list(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)
# Original solution
def main():
    N, K = list(map(int, input().split()))
    A = [0] + list(map(int, input().split()))

    for i in range(N):
        A[i + 1] += A[i]

    B = [A[j] - A[i] for i in range(N) for j in range(i + 1, N + 1)]

    ans = 0
    t = 40
    tmp = pow(2, t)
    while t:
        count = 0
        tmp //= 2
        for b in B:
            if ((b & (tmp + ans)) == (tmp + ans)):
                count += 1
            if count >= K:
                ans += tmp
                break
        t -= 1

    print (ans)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    N, K = list(map(int, input().split()))
    A = [0] + list(map(int, input().split()))

    for i in range(N):
        A[i + 1] += A[i]

    B = [A[j] - A[i] for i in range(N) for j in range(i + 1, N + 1)]

    ans = 0
    tmp = pow(2, 40)
    for _ in range(40):
        count = 0
        tmp //= 2
        tmp_ = ans + tmp
        for b in B:
            if ((b & (tmp_)) == (tmp_)):
                count += 1
            if count >= K:
                ans += tmp
                break

    print (ans)

if __name__ == '__main__':
    main()