let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let hs = Array.init (n + 1) @@ function
    | 0 -> 0
    | _ -> Scanf.scanf "%d " @@ fun h -> h in
  let dp = Array.init (n + 1) @@ fun _ ->
    Array.make_matrix (n + 1) (k + 1) 10000000000000 in
  dp.(0).(0).(0) <- 0;
  for i = 1 to n do
    for k' = 0 to k do
      for j = 0 to n do
        dp.(i).(i).(k') <-
          min dp.(i).(i).(k') @@
          max 0 (hs.(i) - hs.(j)) + dp.(i - 1).(j).(k')
      done
    done;
    for k' = 1 to k do
      for j = 0 to n do
        dp.(i).(j).(k') <-
          min dp.(i).(j).(k') @@
          dp.(i - 1).(j).(k' - 1)
      done
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left min) max_int dp.(n)
