N, K = gets.split.map(&:to_i)
V = $<.read.split.map(&:to_i)
r = 0; left = V.map { |x| r+= x }.unshift(0)
r = 0; right = V.reverse.map{ |x| r+= x}.unshift(0)
vsum = V.inject(:+)

#p ["V",V]
#p ["l",left]
#p ["r",right]
res = -1 << 30
tmp1 = tmp2 = tmp3 = 0
0.upto(K) do |k|
	s, t = K-k ,k 
	v = V.dup
#	p ["s,t",s,t]
	s.times do |i|
		q, r = s-i, i
		tmp1 = V[0...q]
		tmp2 = V[N-r..N-1]
#		p ["q,r",q,r,tmp1,tmp2,(tmp1+tmp2).min(t) ]
		x = (tmp1+tmp2).inject(:+) || 0
		y = (tmp1+tmp2).min(t).inject(:+) || 0
#		p [x,y,x-=y]
		res < x && res = x
#		tmp1 = left[q]
#		tmp2 = right[r]
#		p ["q,r,left,right",q,r,tmp1,tmp2,tmp=V[0...q]+V[N-r..N-1],tmp3=tmp.max(k) << 0]
#
#		p		vsum-tmp1-tmp2+tmp3.inject(:+)
		

	end
end

p res
