#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++){
dp[1][i]=max(dp[1][i],data[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][j+m],dp[1][j]+data[i]);
}
for(int j=0;j<i;j++){
if(j<=i-m+1){
dp[1][i+1]=max(dp[1][i+1],dp[1][j]+data[i]);
}
dp[1][j+m]=max(dp[1][j+m],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+PmRhdGFbaV07Cgl9CgkKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWRwWzFdW2ldP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