program abc145f
    implicit none
    integer N,K
    integer,allocatable::H(:)
    integer(16) ans
    integer(16),allocatable::DP(:,:)
    integer i,j,l

    read*,N,K
    allocate(H(0:N),DP(0:N,0:N))
    H(0)=0
    read*,H(1:N)
    DP=huge(dp)/2
    dp(0,0)=0
    do i=1,N
        do j=1,N
            do l=0,i-1
                dp(i,j)=min(dp(i,j),dp(l,j-1)+max(0,H(i)-H(l)))
            end do
        end do
    end do
    ans=huge(ans)
    do i=0,N
        ans=min(ans,dp(i,N-K))
    end do
    print"(i0)",ans
    
end program abc145f
