module Main where

import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, mapMaybe)
import Control.Monad (replicateM, forM_, foldM)
import qualified Data.Vector.Mutable as MV
import Data.List (sortOn, sort)
import Debug.Trace

readTuple2 :: IO (Int, Int)
readTuple2 = do
    [x, y] <- readInts
    pure (x, y)

readInts :: IO [Int]
readInts = do
    is <- BC.words <$> BC.getLine
    pure $ fst <$> mapMaybe BC.readInt is

main = do
    (n, k) <- readTuple2
    vs <- readInts
    let maxOpTimes = min n k
    let reversedVs = reverse vs
    let ab = [(a, b)|a <- [0..maxOpTimes], b <- [0..(maxOpTimes - a)]]
    let points = fmap (\(a, b) -> let
            av = (take a vs)
            bv = (take b reversedVs)
            v = sort $ av ++ bv
            minusNum = length $ filter (<0) v
            droppableTimes = k - a - b
            dropTimes = min minusNum droppableTimes
            in
                sum $ drop dropTimes v
         ) ab
    print $ maximum points