import Data.Bits

accumulatedSum :: [Int] -> [Int]
accumulatedSum [] = []
accumulatedSum [x] = [x]
accumulatedSum (x:y:rs) = x:accumulatedSum ((y + x):rs)

solve :: Int -> Int -> [Int] -> Int
solve k 0 a = 0
solve k i a
  | k <= length b = s .|. solve k (i - 1) b
  | otherwise = solve k (i - 1) a
    where
      s = shift 1 $ i - 1
      b = [x | x <- a, (x .&. s) /= 0]

beauties :: [Int] -> [Int]
beauties [x] = []
beauties (x:rs) = [y - x | y <- rs] ++ beauties rs

main :: IO ()
main = do
  [_, k] <- (fmap (\x -> read x :: Int)) . words <$> getLine
  a <- (fmap (\x -> read x :: Int)) . words <$> getLine
  let b = accumulatedSum a in
    print $ solve k 40 $ beauties (0:b)
