#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const int mx = 200010;
const long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (int i = (int)(0); i < (int)(n); ++i) {
    cin >> a[i];
  }
  long long cur = 0;
  for (int i = (int)(0); i < (int)(m); ++i) cur += a[i];
  long long maxi = cur;
  int pos = 0;
  for (int i = (int)(m); i < (int)(n); ++i) {
    cur += a[i] - a[i - m];
    if (maxi < cur) {
      maxi = cur;
      pos = i - (m - 1);
    }
  }
  long long ans1 = 0;
  for (int i = (int)(0); i < (int)(n); ++i) {
    if (pos <= i && i < pos + m) {
      ans1 += a[i];
      continue;
    }
    if (a[i] > 0) {
      ans1 += a[i];
      continue;
    }
  }
  cur = 0;
  for (int i = (int)(0); i < (int)(m); ++i) cur += a[i];
  long long mini = cur;
  pos = 0;
  for (int i = (int)(m); i < (int)(n); ++i) {
    cur += a[i] - a[i - m];
    if (mini > cur) {
      mini = cur;
      pos = i - (m - 1);
    }
  }
  long long ans2 = 0;
  for (int i = (int)(0); i < (int)(n); ++i) {
    if (pos <= i && i < pos + m) {
      continue;
    }
    if (a[i] > 0) {
      ans2 += a[i];
      continue;
    }
  }
  long long ans = max(max(ans1, ans2), 0LL);
  cout << ans << endl;
  return 0;
}
