#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long sum;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n - k + 1; i++) {
    for (int j = i; j <= i + k - 1; j++) {
      if (a[j] > 0) break;
      if (j == i + k - 1) {
        for (int p = i; p <= i + k - 1; p++) {
          a[p] = 0;
        }
      }
    }
  }
  if (n == k) {
    for (int i = 1; i <= n; i++) {
      sum += a[i];
    }
    if (sum > 0)
      cout << sum;
    else
      cout << 0;
    return 0;
  }
  for (int i = 1; i <= n - k; i++) {
    if (a[i] > 0) sum += a[i];
  }
  long long e = 0;
  for (int i = n - k + 1; i <= n; i++) {
    e += a[i];
  }
  if (e > 0)
    cout << sum + e;
  else
    cout << sum;
  return 0;
}
