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

typedef long long ll;

const ll INF = 1e15;

int n,k;
int li[305];

ll memo[305][305][305];

ll dp(int id, int bef, int sisa){
	if(sisa < 0) return INF;
	if(id > n) return 0;
	ll &ret = memo[id][bef][sisa];
	if(ret != -1) return ret;
	ret = min(dp(id+1,bef,sisa-1),dp(id+1,id,sisa) + max(0,li[id] - li[bef]));
	return ret;
}

int main(){
	memset(memo,-1,sizeof(memo));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&li[i]);
	ll ans = dp(1,0,k);
	printf("%lld\n",ans);
	return 0;
}
