#include <bits/stdc++.h>
using namespace std;
int n;
int k;
vector<long long> a;
long long dp[200010];
long long sum[200010];
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 = (0); i <= (n - 1); i++) {
    dp[i + 1] = max(dp[i + 1], dp[i]);
    dp[i + k] = max(dp[i + k], dp[i] + sum[i + k] - sum[i]);
    if (i + k + 1 <= n) dp[i + 1] = max(dp[i + 1], dp[i] + a[i + 1]);
    if (i + k + 1 <= n)
      dp[i + k + 1] = max(dp[i + k + 1], dp[i] + a[i + k + 1]);
  }
  cout << dp[n] << endl;
  return 0;
}
