n,k = gets.chomp.split().map(&:to_i)
a = gets.chomp.split().map(&:to_i)

b = []
c = Array.new(n*(n+1)/2)
n.times do |i|
  cur = 0
  (i..(n-1)).each do |j|
    cur += a[j]
    b.push cur
  end
end

def solve(b,kijun,k)
  i = 0
  b.map{|e| e & kijun}.sort.reverse_each do |e|
    #p [kijun, e]
    kijun &= e
    i += 1
    break if i == k
  end
  kijun
end


b.sort!.reverse!
m=Math.log2(b.first).to_i

ans = solve(b,b.first,k)
b.each do |e|
  if e <= m
    solution = solve(b,e,k)
    #p [solution, b, e, k]
    ans = solution if ans < solution
    m /= 2
  end
end

puts ans