def min(a,b); a < b ? a : b; end
def max(a,b); a > b ? a : b; end
N,K = gets.split.map(&:to_i)
H = Array.new(N + 1, 0).tap do |it| 
  gets.split.map(&:to_i).each_with_index do |h,i|
    it[i + 1] = h
  end
end
dp = Array.new(N + 1){ Array.new(K + 1, Float::INFINITY) }
dp[0].fill(0)

(1 .. N).each do |n|
  (0 .. min(n - 1, K)).each do |k|
    (0 .. k).each do |i|
      n_ = n - i - 1
      dp[n][k] = min(dp[n_][k - i] + max(H[n] - H[n_], 0), dp[n][k])
    end
  end
end
puts dp[N].min

