local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local function dbgpr_t(tbl, use_pairs)
    if DBG then
        local enum = ipairs
        if use_pairs then
            enum = pairs
        end
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in enum(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

----
local N, Kmax = io.read("n", "n")
local V = {}
for i=1,N do
    V[i] = io.read("n")
end

local lim_left = math.min(N, Kmax)
local ans = 0
for a=0, lim_left do
    local got_left = {}
    local lim_right = math.min(N-a, Kmax-a)
    assert(lim_right >= 0)
    for i=1,a do
        got_left[i] = V[i]
    end
    for b=0, lim_right do
        local got = {table.unpack(got_left)}
        for i=1,b do
            got[#got + 1] = V[N+1-i]
        end
        table.sort(got)
        local ndiscard = Kmax - a - b
        local ndiscard_orig = ndiscard
        assert(ndiscard >= 0)
        local value = 0
        for i=1, #got do
            if got[i] < 0 and ndiscard > 0 then
                ndiscard = ndiscard - 1
            else
                value = value + got[i]
            end
        end
        dbgpr(a, b, #got, ndiscard_orig, value)
        ans = math.max(ans, value)
    end
end
print(ans)