n,k = gets.chomp.split().map(&:to_i)
a = gets.chomp.split().map(&:to_i)

b = []
c = Array.new(n*(n+1)/2)
n.times do |i|
  cur = 0
  (i..(n-1)).each do |j|
    cur += a[j]
    b.push cur
  end
end

def solve(b,kijun,k)
  i = 0
  b.map{|e| e & kijun}.sort.reverse_each do |e|
    #p [kijun, e]
    kijun &= e
    i += 1
    break if i == k
  end
  kijun
end

b.sort!
last = b.pop
k-=1
puts solve(b,last,k)
