#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
long long int dp[2][10003];
long long int data[10003];
int main() {
// your code goes here
int n,m;
memset(dp,0,sizeof(dp));
memset(data,0,sizeof(data));
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>data[i];
}
for(int i=0;i<n;i++){
for(int j=max(0,i-m+1);j<i;j++){
dp[0][i+m]=max(dp[0][i+m],dp[1][j]+data[i]);
dp[1][j+m]=max(dp[1][i],dp[1][j]+data[i]);
}
for(int j=0;j<=i;j++){
dp[1][i]=max(dp[1][i],dp[0][j]+data[i]);
dp[0][i+m]=max(dp[0][i+m],dp[0][j]+data[i]);
}
for(int j=0;j<2;j++){
dp[j][i+1]=max(dp[j][i+1],dp[j][i]);
}
//for(int j=0;j<10;j++){
// cout<<j<<"("<<dp[0][j]<<" "<<dp[1][j]<<")";
//}
//cout<<endl;
}
long long int ans=0;
for(int i=0;i<2*n+3;i++){
for(int j=0;j<2;j++){
ans=max(ans,dp[j][i]);
}
}
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsb25nIGxvbmcgaW50IGRwWzJdWzEwMDAzXTsKbG9uZyBsb25nIGludCBkYXRhWzEwMDAzXTsKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgbixtOwoJbWVtc2V0KGRwLDAsc2l6ZW9mKGRwKSk7CgltZW1zZXQoZGF0YSwwLHNpemVvZihkYXRhKSk7CgljaW4+Pm4+Pm07Cglmb3IoaW50IGk9MDtpPG47aSsrKXsKCQljaW4+PmRhdGFbaV07Cgl9CgkKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWZvcihpbnQgaj1tYXgoMCxpLW0rMSk7ajxpO2orKyl7CgkJCWRwWzBdW2krbV09bWF4KGRwWzBdW2krbV0sZHBbMV1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