#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]);
long long int d=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]+d);
dp[0][i+m]=max(dp[0][i+m],dp[1][j]+d);
}else{
dp[1][j+m]=max(dp[1][j+m],dp[1][j]+d);
dp[0][i+m]=max(dp[0][i+m],dp[1][j]+d);
}
dp[1][i+1]=max(dp[1][i],dp[0][j]+d);
dp[0][i+m]=max(dp[0][i+m],dp[0][j]+d);
}
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+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Q1ODcgNjc3MzEzMTY5IDIyMjIzNjc4NyA4MDI4NTIyMzMgNjQ4MDY3OTA4IDc0MTg4MzU1MiAyNjgwMzEyODAgNDQ0NDc2NDQ4IDcyNzQ5NDAyIDQ4NzIwNTIzOCA4NDQzMDUxIDE3MzUzMTMwMSA5NzIwODM5NjggMTg1OTg1MDA4IDg1NDk0NzcwCg==
19 6
649709806 544965184 989973157 70782669 896694587 677313169 222236787 802852233 648067908 741883552 268031280 444476448 72749402 487205238 8443051 173531301 972083968 185985008 85494770