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
two = [2]
for i in 0..29
  two.push(two[-1]*2)
  if two[-1] > bi[-1]
    two.delete_at(-1)
    break
  end
end
two.push(0)

minus = 0
res = []
for j in 1..3
  minus += two[-j]
  ans = (bi[-1] - minus)
  for i in 2..n2
    ans = (ans & (bi[-i] - minus))
  end
  res.push(ans)
  if two[-j] == 2
    break
  end
end
res = res.sort
puts res[-1]
