object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, K = sc.nextInt
  val Hs = Array(0) ++ Array.fill(N)(sc.nextInt) ++ Array(0)
  var dp = Array.fill(N + 2, N + 1)(1000000000000L)
  dp(0)(0) = 0
  for(i <- 0 to N + 1) {
    for(j <- 0 until i) {
      val p = i - j - 1
      for(s <- 0 to K - p) {
        val t = dp(j)(s) + (if(Hs(i) > Hs(j)) Hs(i) - Hs(j) else 0)
        if(dp(i)(s + p) > t) dp(i)(s + p) = t
      }
    }
  }
  println(dp(N + 1).min)
}