import Data.Bits
import Data.List
main = do
  [n,k] <- map read . words <$> getLine
  as <- map read . words <$> getLine :: IO [Integer]
  let step xs i
        | length ys < k = xs
        | otherwise = ys
        where ys = filter (`testBit` i) xs
      bs = concatMap (scanl (+) 0) $ init $ tails as
  print $ foldl1 (.&.) $ foldl step bs [40,39..0]