import Data.List

main = do
  [n,k]<-map read.words<$>getLine
  vs <- map read.words<$>getLine
  print $ solve n k vs

solve :: Int->Int->[Int]->Int
solve n k vs = maximum ans
  where
  ss = map g ses
  ses = [(a,b)|a<-[0..n],b<-[a..n],b-a>=n-k]
  g (a,b) = take a vs ++ drop b vs
  ans = map f ss
  f s = go (k-length s) s'
    where
    go _ [] = 0
    go 0 s = sum s
    go n (e:s)
      | e<0 = go (n-1) s
      | otherwise = e + go n s
    s' = sort s