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**12)}
dp[0][0] = 0
(1 .. N + 1).each do |i|
  (0 ... i).each do |j|
    p = i - j - 1
    (0 .. K - p).each do |k|
      t = dp[j][k] + (H[i] > H[j] ? H[i] - H[j] : 0)
      dp[i][k + p] = t if dp[i][k + p] > t
    end
  end
end
puts dp[N + 1].min