local mmi, mma = math.min, math.max
local n, k = io.read("*n", "*n")
local v = {}
for i = 1, n do
  v[i] = io.read("*n")
end
local leftsum = {v[1]}
for i = 2, n do
  leftsum[i] = leftsum[i - 1] + v[i]
end
local rightsum = {}
for i = 1, n do rightsum[i] = 0 end
rightsum[n] = v[n]
for i = n - 1, 1, -1 do
  rightsum[i] = rightsum[i + 1] + v[i]
end
local dpleft = {}
for i = 1, n do
  dpleft[i] = {}
  local val = leftsum[i]
  local tmp = {}
  for j = 1, i do
    tmp[j] = v[j]
  end
  table.sort(tmp)
  for j = 1, i do
    val = val - tmp[j]
    dpleft[i][j] = val
  end
end

local dpright = {}
for i = 1, n do
  dpright[i] = {}
  local val = rightsum[i]
  local tmp = {}
  for j = i, n do
    tmp[j - i + 1] = v[j]
  end
  table.sort(tmp)
  for j = 1, n + 1 - i do
    val = val - tmp[j]
    dpright[i][j] = val
  end
end

for i = 1, n do
  dpleft[i][1] = mma(dpleft[i][1], leftsum[i])
  for j = 2, #dpleft[i] do
    dpleft[i][j] = mma(dpleft[i][j], dpleft[i][j - 1])
  end
  if i < n then
    for j = 1, #dpleft[i] do
      dpleft[i + 1][j] = mma(dpleft[i + 1][j], dpleft[i][j])
    end
  end
end

for i = n, 1, -1 do
  dpright[i][1] = mma(dpright[i][1], rightsum[i])
  for j = 2, #dpright[i] do
    dpright[i][j] = mma(dpright[i][j], dpright[i][j - 1])
  end
  if 1 < i then
    for j = 1, #dpright[i] do
      dpright[i - 1][j] = mma(dpright[i - 1][j], dpright[i][j])
    end
  end
end
local ret = 0
do
  for i = n, 1, -1 do
    local z = n + 1 - i
    if z < k then
      ret = mma(ret, dpright[i][mmi(k - z, z)])
    elseif z == k then
      ret = mma(ret, rightsum[i])
    else
      break
    end
  end
end
for il = 1, n do
  do
    if il <= k then
      ret = mma(ret, leftsum[il])
    end
    local rightuse = k - il
    for i = n, il + 1, -1 do
      local z = n + 1 - i
      if z < rightuse then
        ret = mma(ret, leftsum[il] + dpright[i][mmi(rightuse - z, z)])
      elseif z == rightuse then
        ret = mma(ret, leftsum[il] + rightsum[i])
      else
        break
      end
    end
  end
  for j = 1, il do
    local leftuse = il + j
    if leftuse <= k then
      ret = mma(ret, dpleft[il][j])
    end
    local rightuse = k - leftuse
    for i = n, il + 1, -1 do
      local z = n + 1 - i
      if z < rightuse then
        ret = mma(ret, dpleft[il][j] + dpright[i][mmi(rightuse - z, z)])
      elseif z == rightuse then
        ret = mma(ret, dpleft[il][j] + rightsum[i])
      else
        break
      end
    end
  end
end
print(ret)
