local n,k=io.read("n","n")
local v={}
for i=1,n do
    v[i]=io.read("n")
end

local m=math.min(n,k)
local answer=0
for i=0,m do
    for j=0,m-i do
        local t={}
        local sum=0
        for l=1,i do
            table.insert(t,v[l])
            sum=sum+v[l]
        end
        for l=n-j+1,n do
            table.insert(t,v[l])
            sum=sum+v[l]
        end
        table.sort(t)
        for l=1,math.min(k-i-j,#t) do
            if t[l]<0 then
                sum=sum-t[l]
            end
        end
        answer=math.max(answer,sum)
    end
end
print(answer)