{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Int
solve !n !k !vn = maximum
  [ calc i a b | i <- [0 .. k], a <- [0 .. i], let b = i - a ]
 where
  calc !i !a !b =
    let (a1, a2) =
          (\vec -> (VU.filter (> 0) vec, VU.filter (< 0) vec)) $ VU.take a vn
        (b1, b2) =
          (\vec -> (VU.filter (> 0) vec, VU.filter (< 0) vec))
            $ VU.take b
            $ VU.reverse vn
        r = sum $ drop (k - i) $ sort $ VU.toList a2 ++ VU.toList b2
    in  VU.sum a1 + VU.sum b1 + r


main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, k) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  vn <- VU.unfoldrN n readInt <$> B.getLine

  print $ solve n k vn
