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

b = []
n.times do |i|
  cur = 0
  (i..(n-1)).each do |j|
    cur += a[j]
    b.push cur
  end
end
b.sort!.reverse!
#p b

ans = b.first
k.times do |i|
  ans = ans & b[i]
end

p ans