N, K = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)

require 'pp'
def debug obj
  PP.pp obj, STDERR
end
debug [N,K]
debug A
sum = 0
sumA = A.map{|a| sum += a }
bt_list = []

(0..(N)).to_a.combination(2) do |l,r|
  bt_list.push(((sumA[r] || 0) - sumA[l]).abs)
end

bt_list.sort!.reverse!
debug bt_list

r = 0

max = sumA.last

maxlog = Math.log2(max).to_i
maxlog.downto(1) do |i|
  count = 0
  ra = r + (1 << i)
  bt_list.each_with_index do |bt, i|
    if ra == ( ra & bt )
      count += 1
      if count >= K
        r = ra
        break
      elsif (bt_list.size - i -1) < K - count
        break
      end
    end
  end
end

puts r