#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][j+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[0][i+m]=max(dp[0][i+m],dp[0][j]+data[i]);
dp[1][i+1]=max(dp[1][i+1],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<13;j++){
cout<<j<<"("<<dp[0][j]<<" "<<dp[1][j]<<")";
}
cout<<endl;
}
long long int ans=0;
for(int i=0;i<2*n+4;i++){
for(int j=0;j<2;j++){
ans=max(ans,dp[j][i]);
}
}
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsb25nIGxvbmcgaW50IGRwWzJdWzEwMDAzXTsKbG9uZyBsb25nIGludCBkYXRhWzEwMDAzXTsKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgbixtOwoJbWVtc2V0KGRwLDAsc2l6ZW9mKGRwKSk7CgltZW1zZXQoZGF0YSwwLHNpemVvZihkYXRhKSk7CgljaW4+Pm4+Pm07Cglmb3IoaW50IGk9MDtpPG47aSsrKXsKCQljaW4+PmRhdGFbaV07Cgl9CgkvL+OBmuOBo+OBqOmgreOBjOO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