lines = readlines.map{|line| line.split(' ').map(&:to_i)}
b=[]
c=[]
for i in 0..lines[0][0]-1
  for j in i..lines[0][0]-1
    a=0
    for k in i..j
      a=a+lines[1][k]
    end
    b.push(a)
  end
end
b=b.combination(lines[0][1]).to_a
for l in 0..b.length-1
  d=b[l][0]
  for m in 1..lines[0][1]-1
    d=d&b[l][m]
  end
  c.push(d)
end
p c.max