n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ary = [0]
n.times do |i|
  ary[i+1]= a[i] + ary[i]
end
beauty = []
n.times do |i|
  (n-i).times do |j|
    beauty << ary[i+j+1]-ary[i]
  end
end
beauty.sort!
max = beauty[-1]
digit = 0
while max > 0
  digit += 1
  max /= 2
end
digit.times do |i|
  check = 2 ** (digit-i-1)
  cnt = 0
  newBeauty = []
  beauty.each do |v|
    if v & check > 0
      cnt += 1
      newBeauty << v
    end
  end
  if cnt >= k
    beauty = newBeauty
  end
end
beauty.reverse!
ans = beauty[0]
(k-1).times do |i|
  ans &= beauty[i+1]
end
p ans