import Data.Bool
import Data.List

solve :: Int -> Int -> [Int] -> Int
solve n k a = fst $ foldr f (0, sums) [0..39] where
  sums = concatMap (scanl1 (+)) $ init $ tails a 
  f e (c, sums)
    | length ok >= k = (nc, ok)
    | otherwise = (c, sums)
    where
      ok = filter (>= nc) sums
      nc = c + 2^e

main = do
  [n,k] <- readWords
  a <- readWords
  print $ solve n k a

readWords = map read . words <$> getLine