import Data.List

main :: IO ()
main = do
  [n,k] <- map (read :: String -> Int) . words <$> getLine
  vn <- map (read :: String -> Int) . words <$> getLine
  print $ ans n k vn

ans :: Int -> Int -> [Int] -> Int
ans n k vn = maximum $ map (pickup n k vn) $ allComb n k

pickup :: Int -> Int -> [Int] -> (Int,Int) -> Int
pickup n k vn (a,b) = sum $ func 0 xs where
  p = k-a-b
  xs = sort $ (take a vn) ++ (drop (n-b) vn)
  func _ [] = []
  func m (l:ls)
    | m == p = l:ls
    | l >= 0 = l:ls
    | l < 0 = func (m+1) ls

allComb :: Int -> Int -> [(Int,Int)]
allComb n k = concat $ map func ms where
  func l = zip [0..l] [l,l-1..0]
  ms = [0..min n k]