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 inf = 1000000007 * (n + 2)
local t = {}
for i = 1, n + 2 do
  t[i] = {}
  for j = 1, k + 1 do
    t[i][j] = inf
  end
end
t[1][1] = 0
for dst = 2, n + 2 do
  for src = 1, dst - 1 do
    local midlen = dst - src - 1
    local score = mma(0, h[dst] - h[src])
    for z = 1, k + 1 - midlen do
      t[dst][z + midlen] = mmi(t[dst][z + midlen], t[src][z] + score)
    end
  end
end

local ret = t[n + 2][1]
for i = 2, k + 1 do
  ret = mmi(ret, t[n + 2][i])
end
print(ret)
