import Data.List

f2::Int->[Int]->Int
f2 _ []=0
f2 0 xs=sum xs
f2 k (x:xs)
    |x>=0=sum (x:xs)
    |otherwise=f2 (k-1) xs

f::Int->[[Int]]->[Int]
f _ []=[]
f k (x:xs)=(f2 (k-(length x)) x):f k xs

main = do
       t1<-getLine
       t2<-getLine
       let n:k:[]=map read (words t1)::[Int]
           js=map read (words t2)::[Int]
           ps=[sort ((take e1 js)++(drop (n-e2) js))|e1<-[0..n],e2<-[0..n],e1+e2<k+1,e1+e2<n+1]
       print $ maximum $ f k ps