N,K,*A=`dd`.split.map(&:to_i)
s = [0]
A.each{ |a| s << (s[-1] + a)}
ps = (0...N).map{ |i| (i...N).map{ |j| s[j+1]-s[i] } }.flatten
ans = 0
(0..40).reverse_each{ |k|
  b = 1 << k
  ns = ps.select{ |x| x & b > 0 }
  next if ns.size < K
  ans += b
  ps = ns
}
p ans
