#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll N=105,INF=1e9;
ll a[N],b[N],y,z,x,n,q,mx,mn,k,ans,ind;
pair <ll,ll> dp[N][N];
bool ok,okk;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin >> n >> q;
for (int i=1; i<=n; i++) cin >> a[i];
for (int i=1; i<=n; i++){
for (int k=1; k<=n; k++){
dp[i][k]=mp(INF,0);
}
}
dp[0][0]=mp(0,0);
for (int i=1; i<=n; i++){
for (int k=1; k<=n; k++){
if (k>i) continue;
if (a[i]>dp[i-1][k].s){
if (dp[i][k].f>dp[i-1][k].f-dp[i-1][k].s+a[i])
dp[i][k]=mp(dp[i-1][k].f-dp[i-1][k].s+a[i],a[i]);
}
else{
if (dp[i][k].f>dp[i-1][k].f){
dp[i][k]=dp[i-1][k];
}
}
mx=a[i];
for (int j=i-1; j>=1; j--){
x=dp[j][k-1].f+mx;
if (x<dp[i][k].f){
dp[i][k]=mp(x,mx);
}
mx=max(mx,a[j]);
}
// cout<<i<<" "<<k<<" "<<dp[i][k].f<<" "<<dp[i][k].s<<endl;
}
}
cout<<dp[n][q].f<<endl;
}