#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  long long rsl = 0;
  long long a[N];
  for (int i = (int)0; i < (int)N; i++) {
    cin >> a[i];
    if (i < N - K) {
      a[i] = max(0ll, a[i]);
      rsl += max(0ll, a[i]);
    }
  }
  long long ruiseki[K];
  memset(ruiseki, 0, sizeof(ruiseki));
  long long tmp = 0;
  for (int i = (int)0; i < (int)K; i++) {
    tmp += a[N - K - i];
  }
  ruiseki[0] = tmp;
  for (int i = (int)1; i < (int)K; i++) {
    ruiseki[i] = ruiseki[i - 1] - a[N - K + i - K] + a[N - K + i];
  }
  rsl += ruiseki[K - 1];
  for (int i = (int)0; i < (int)K; i++) {
    if (a[N - K + i] < 0 and ruiseki[i] < 0) rsl -= ruiseki[i];
  }
  cout << rsl << endl;
}
