N, K = gets.split.map(&:to_i)
H = [0] + gets.split.map(&:to_i) + [0]

dp = Array.new(N + 2){Array.new(N + 1, 10**10)}
dp[0][0] = 0
f = ->(i, j){H[j] > H[i] ? H[j] - H[i] : 0}
(1 .. N + 1).each do |i|
  (0 ... i).each do |j|
    p = i - j - 1
    (0 .. K - p).each do |k|
      dp[i][k + p] = dp[j][k] + f[j, i] if dp[i][k + p] > dp[j][k] + f[j, i]
    end
  end
end
puts dp[N + 1].min