program laminate
  implicit none
  integer(8), parameter :: inf = 10000000000000000_8
  integer :: n, k, i, j, l
  integer(8) :: h(0:300) = 0_8, dp(0:300,0:300) = inf
  read(*,*) n, k
  read(*,*) h(1:n)
  dp(:,0) = 0_8
  do i = 1, n
    do j = 1, min(i,n-k)
      do l = 0, i-1
        dp(i,j) = min(dp(i,j),dp(l,j-1)+max(0_8,h(i)-h(l)))
      end do
    end do
  end do
  write(*,'(i0)') minval(dp(1:n,n-k))
end program laminate