#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
struct Edge {
  LL to, cost;
};
LL h, w, n, m, s = INF, k, sum, ans = 0, t[1000000], a[1000000];
string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
bool flag;
int main() {
  cin >> n >> m;
  t[0] = 0;
  for (LL i = 0; i < n; i++) {
    w = 0;
    cin >> a[i];
    if (a[i] < 0) t[i + 1] = -a[i];
    t[i + 1] += t[i];
    if (a[i] > 0) sum += a[i];
    if (i >= m) {
      s = min(s, t[i + 1] - t[i - m + 1]);
    }
    if (a[i] > 0) {
      h++, k = 0;
    } else if (a[i] < 0) {
      k++, h = 0;
    } else {
      k++, h++;
    }
    if (k == m || h == m) flag = 1;
  }
  cout << (flag == 1 ? sum : sum - s) << endl;
  return 0;
}
