import Data.List
import Control.Monad

getVals :: Read a => IO [a]
getVals = getLine >>= (return . map read . words)
getStrs = getLine >>= (return . words)

solve k vs = maximum [calc a b k vs | a <- [0..k], b <- [0..k-a]]
calc a b k vs = sum largest
    where
        largest = take (max n_positive $ 2*a+2*b-k) $ reverse $ sort full
        n_positive = length $ filter (\x -> x >= 0) full
        full = (take a vs) ++ (take b $ reverse vs)

main = do
    [n, k] <- getVals :: IO [Int]
    vs <- getVals :: IO [Integer]
    print $ solve k vs