#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int f[10002];
int i,j,n,m;
int a[10002];
int s[10002];
int maxx(int a,int b){
return a>b?a:b;
}
int minx(int a,int b){
return a<b?a:b;
}
int main()
{
freopen("cowrun.in","r",stdin);
freopen("cowrun.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++){
scanf("%d",&a[i]);
s[i]=s[i-1]+a[i];
}
for (i=1;i<=n;i++){
f[i]=f[i-1];
for (int j=1;j<=m&&j+j<=i;j++)
if (f[i-2*j]+s[i-j]-s[i-2*j]>f[i])
f[i]=f[i-2*j]+s[i-j]-s[i-2*j];
}
printf("%d",f[n]);
return 0;
}