#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
long long arr[MAX];
int n, k;
long long dp[MAX], bestdp[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  long long sum = 0;
  for (int i = n - 1; i >= 0; --i) {
    sum += arr[i];
    if (sum < 0) sum = 0;
    dp[i] = bestdp[i + k] + sum;
    bestdp[i] = max(bestdp[i + 1], dp[i]);
  }
  return cout << bestdp[0] << "\n", 0;
}
