#include <bits/stdc++.h>
using namespace std;

#define int long long

int a[310];
int memo[310][310][310];
int n;

int dp(int i, int k, int l){
    if(i == n){
        return 0;
    }

    if(memo[i][k][l] != -1){
        return memo[i][k][l];
    }

    int ans = LLONG_MAX;

    if(k > 0){
        ans = min(ans, dp(i+1, k-1, l+1));
    }


    if(i-l-1 < 0 || a[i-l-1] < a[i]){
        ans = min(ans, dp(i+1, k, 0) + a[i]-(i-l-1 >= 0 ? a[i-l-1] : 0));
    }else{
        ans = min(ans, dp(i+1, k, 0));
    }

    return memo[i][k][l] = ans;
}

signed main(){
    int k;
    cin >> n >> k;

    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    memset(memo, -1, sizeof(memo));

    cout << dp(0, k, 0) << endl;
    return 0;
}