#include <bits/stdc++.h>
using namespace std;
int n;
int k;
vector<long long> a;
long long dp[100010];
long long sum[100010];
int main() {
  dp[0] = 0;
  cin >> n >> k;
  a.resize(n + 1, 0);
  for (int i = (1); i <= (n); i++) cin >> a[i];
  for (int i = (1); i <= (n); i++) sum[i] = sum[i - 1] + a[i];
  for (int i = (1); i <= (n); i++) {
    dp[i] = max(dp[i], dp[i - 1]);
    if (i - k > 0) dp[i] = max(dp[i], dp[i - k] + sum[i] - sum[i - k]);
    if (i + k <= n) dp[i] = max(dp[i], dp[i - 1] + a[i]);
    if (i + k <= n) dp[i + k] = max(dp[i + k], dp[i - 1] + a[i + k]);
  }
  cout << dp[n] << endl;
  return 0;
}
