input = gets.split("\s").map(&:to_i)
a = gets.split("\s").map(&:to_i)
array = []
start = 0
len = input[0]
while true do 
  array.push(a.slice(start, len).inject(:+))
  start += 1
  if start + len > input[0]
    start = 0
    len -= 1
    break if array.length >= input[1]
  end
end

array.sort!.reverse!
ans = array.shift
(input[1] - 1).times do |n|
  ans &= array[n]
end
puts ans