import Data.List
main=do
 [n,k]<-map read.words<$>getLine
 v<-map read.words<$>getLine
 (print.maximum.(map (g n k v))) [(l,r)|l<-[0..k],r<-[0..k],l+r<=(min k n)]
  where g n k v (l,r) = h (sort((take l v)++(drop (n-r) v))) (k-l-r)
        h l 0 = sum l
        h [] _ = 0
        h l k = if (head l)<0 then (h (tail l) (k-1)) else (sum l)