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

values = Array.new((N + 1)*N/2)
index = 0
for i in 0...N do
    sum = 0
    for j in i...N do
        sum += a[j]
        values[index] = sum
        index += 1
    end
end

sorted = values.sort_by{|i| -i}
max = 0
for i in 0...(N - K) do
    if max >= sorted[i] then
        break
    end
    max = [max, sorted[i, K].inject{|a, b| a & b}].max
end

p max
