#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
// your code goes here
int n,m;
long long int data[10003];
long long int dp[2][10003];
memset(data,0,sizeof(data));
memset(dp,0,sizeof(dp));
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=0;j<i;j++){
long long int d=data[i]+dp[1][j];
long long int d2=data[i]+dp[0][j];
if(j<=i-m+1){
dp[1][i+1]=max(dp[1][i+1],d);
}else if(i<=j+m){
dp[1][j+m-1]=max(dp[1][j+m-1],d);
}
dp[1][i+1]=max(dp[1][i+1],d2);
dp[0][i+m-1]=max(dp[0][i+m-1],d2);
}
dp[1][i+1]=max(dp[1][i+1],dp[1][i]);
dp[0][i+1]=max(dp[0][i+1],dp[0][i]);
}
long long int ans=0;
for(int i=0;i<n*2+3;i++){
ans=max(ans,dp[0][i]);
ans=max(ans,dp[1][i]);
}
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJaW50IG4sbTsKCWxvbmcgbG9uZyBpbnQgZGF0YVsxMDAwM107Cglsb25nIGxvbmcgaW50IGRwWzJdWzEwMDAzXTsKCW1lbXNldChkYXRhLDAsc2l6ZW9mKGRhdGEpKTsKCW1lbXNldChkcCwwLHNpemVvZihkcCkpOwoJY2luPj5uPj5tOwoJZm9yKGludCBpPTA7aTxuO2krKyl7CgkJY2luPj5kYXRhW2ldOwoJfQoJZm9yKGludCBpPTA7aTxuO2krKyl7CgkJZHBbMV1baV09bWF4KGRwWzFdW2ldLGRhdGFbaV0pOwoJCWZvcihpbnQgaj0wO2o8aTtqKyspewoJCQlsb25nIGxvbmcgaW50IGQ9ZGF0YVtpXStkcFsxXVtqXTsKCQkJbG9uZyBsb25nIGludCBkMj1kYXRhW2ldK2RwWzBdW2pdOwoJCQlpZihqPD1pLW0rMSl7CgkJCQlkcFsxXVtpKzFdPW1heChkcFsxXVtpKzFdLGQpOwoJCQl9ZWxzZSBpZihpPD1qK20pewoJCQkJZHBbMV1baittLTFdPW1heChkcFsxXVtqK20tMV0sZCk7CgkJCX0KCQkJCgkJCQoJCQlkcFsxXVtpKzFdPW1heChkcFsxXVtpKzFdLGQyKTsKCQkJZHBbMF1baSttLTFdPW1heChkcFswXVtpK20tMV0sZDIpOwoJCX0KCQlkcFsxXVtpKzFdPW1heChkcFsxXVtpKzFdLGRwWzFdW2ldKTsKCQlkcFswXVtpKzFdPW1heChkcFswXVtpKzFdLGRwWzBdW2ldKTsKCX0KCWxvbmcgbG9uZyBpbnQgYW5zPTA7Cglmb3IoaW50IGk9MDtpPG4qMiszO2krKyl7CgkJYW5zPW1heChhbnMsZHBbMF1baV0pOwoJCWFucz1tYXgoYW5zLGRwWzFdW2ldKTsKCX0KCWNvdXQ8PGFuczw8ZW5kbDsKCXJldHVybiAwOwp9
MTIgNQo4NjQ4MTQxNjkgNzE2NjM4Mzc3IDkyNjg4OTE4MyA4OTE0Njg4MjYgMjE3MTM4MzUxIDg5MTk3MjM5NyA1MDQzNzE5MTYgNjc4MTU5OTk1IDQzNTQ3ODYwNCAxODEyNTQyMjUgNzYwODIyODQxIDY4ODUwMjcyOA==
12 5
864814169 716638377 926889183 891468826 217138351 891972397 504371916 678159995 435478604 181254225 760822841 688502728