#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e3+10;
ll n,k,a[N],f[N][N];
int main(){
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
f[1][1]=a[1];
for(int i=2;i<=n;i++){
for(int j=1;j<=k;j++){
f[i][j]=max(f[i-1][j],f[i-2][j-1]+a[i]);
}
}
printf("%lld\n",f[n][k]);
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e3+10;
ll n,k,a[N],f[N][N][2];
int main(){
memset(f,-63,sizeof f);
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=0;i<=n;i++) f[i][0][0]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
f[i][j][0]=max(f[i-1][j][0],f[i-1][j][1]);
f[i][j][1]=max(f[i-1][j-1][0]+a[i],f[i][j][1]);
}
}
printf("%lld\n",max(f[n][k][0],f[n][k][1]));
return 0;
}