import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,k] <- getIntList
    xs <- getIntList
    let ys = reverse xs
    let solve a b = sum ls + sum rs - sum ms
            where ls = take a xs
                  rs = take b ys
                  i = k - a - b
                  ms = take i . takeWhile (< 0) $ sort (ls ++ rs)
    let m = min n k
    let ans = maximum [ solve a b | a <- [0..m], b <- [0..m-a]]
    print ans