local mmi, mma = math.min, math.max
local n, k = io.read("*n", "*n")
local h = {0}
for i = 1, n do
  h[i + 1] = io.read("*n")
end
h[n + 2] = 0
local t = {}
for i = 1, n + 2 do
  t[i] = {}
  for j = 1, k + 1 do
    t[i][j] = 0
  end
end
for i = 2, n + 1 do
  t[i] = {}
  for j = 1, k + 1 do
    t[i][j] = t[i - 1][j]
  end
  for j = i, n + 1 do
    local score = 0
    local tgt = mma(h[i - 1], h[j + 1])
    for z = i, j do
      score = score + mma(0, h[z] - tgt)
    end
    local len = j + 1 - i
    for z = len + 1, k + 1 do
      t[j][z] = mma(t[j][z], t[i - 1][z - len] + score)
    end
  end
end
local ret = -t[n + 1][1]
for i = 2, k + 1 do
  ret = mmi(ret, -t[n + 1][i])
end
for i = 2, n + 1 do
  ret = ret + mma(0, h[i] - h[i - 1])
end
print(ret)
