import Data.List
main=do
 [n,k]<-map read.words<$>getLine
 v<-map read.words<$>getLine
 print$maximum[solve((take i v)++(drop(n-j)v))(k-i-j)|i<-[0..n],j<-[0..n-i],i+j<=k]
solve y k=(sum y)-(sum$take k(filter(0>)$sort y))