import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  [n,k] <- map read.words <$> getLine :: IO [Int]
  vs <- map read.words <$> getLine :: IO [Int]
   ans' <- forM [0..k] $ \k'' -> do
    forM [(k''+1)`div`2..k''] $ \k' -> do
      --putStrLn $ "--- k' = " ++ (show k') ++ " ---"
      forM [1..k'] $ \i -> do --A,B
        let hand = sort $ (take i vs) ++ (drop (n-k'+i) vs)
        --print $ sum $ drop (k-k') hand
        return $ sum $ drop (k-k') hand
  print $ maximum $ concat $ concat ans'
