local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local ior = io.input()
local n, k = ior:read("*n", "*n")
local v = {}
for i = 1, n do v[i] = ior:read("*n") end
local left = {}
local max = 0
for i_a = 0, n do
  local right = {}
  local clim = n - i_a
  for i_c = 0, n - i_a do
    local blim = mmi(i_a, k - i_a - i_c)
    for i_b = 0, blim do
      local dlim = mmi(i_c, k - i_a - i_c - i_b)
      for i_d = 0, dlim do
        local cand = 0
        for i_left = 1, i_a - i_b do
          cand = cand + left[i_left]
        end
        for i_right = 1, i_c - i_d do
          cand = cand + right[i_right]
        end
        max = mma(max, cand)
      end
    end
    if(i_c ~= clim) then
      table.insert(right, v[n - i_c])
      table.sort(right, function(x, y) return x > y end)
    end
  end
  if(i_a ~= n) then
    table.insert(left, v[i_a + 1])
    table.sort(left, function(x, y) return x > y end)
  end
end
print(max)
