n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
z = []
for l in 0..(n - 1)
  x = 0
  for m in l..(n - 1)
    x = x + a[m]
    z << x
  end
end

z.sort!
z.reverse!
result = z[0]
for j in 1..k - 1
  result = result & z[j]
end
puts result
