n1,n2 = gets.chomp.split(" ").map(&:to_i)
ar = gets.chomp.split(" ").map(&:to_i)
bi = []
for i in 0..n1 - 1
  inst = 0
  for j in i..n1 - 1
    inst += ar[j]
    bi.push(inst)
  end
end
bi = bi.sort
ans = bi[-1]
for i in 2..n2
  ans = (ans & bi[-i])
end
puts ans
