#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
long long int dp[3][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);j<=i;j++){
dp[0][i+m]=max(dp[0][i+m],dp[1][j]+data[i]);
dp[1][j+m]=max(dp[1][j+m],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]);
}
dp[1][i]=max(dp[1][i],dp[0][i]+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+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsb25nIGxvbmcgaW50IGRwWzNdWzEwMDAzXTsKbG9uZyBsb25nIGludCBkYXRhWzEwMDAzXTsKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgbixtOwoJbWVtc2V0KGRwLDAsc2l6ZW9mKGRwKSk7CgltZW1zZXQoZGF0YSwwLHNpemVvZihkYXRhKSk7CgljaW4+Pm4+Pm07Cglmb3IoaW50IGk9MDtpPG47aSsrKXsKCQljaW4+PmRhdGFbaV07Cgl9CgkKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWZvcihpbnQgaj1tYXgoMCxpLW0pO2o8PWk7aisrKXsKCQkJZHBbMF1baSttXT1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