#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<long long> v;
long long res = 0;
long long t, tt, ts;
bool b[100010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  while (!v.empty() && v[v.size() - 1] < 1) v.pop_back();
  while (!v.empty() && v[0] < 1) v.erase(v.begin());
  for (int i = 0; i <= v.size() - m; i++) {
    bool fl = 1;
    for (int j = 0; j < m; j++) {
      if (v[i + j] > 0) {
        fl = 0;
        break;
      }
    }
    if (fl)
      for (int j = 0; j < m; j++) b[i + j] = 1;
  }
  if (v.size() <= m) {
    for (int i = 0; i < v.size(); i++) res += v[i];
    cout << max(res, (long long)0);
    return 0;
  }
  for (int i = 0; i < v.size(); i++)
    if (v[i] >= 0) res += v[i];
  for (int i = 0; i < m; i++)
    if (v[i] < 0 && !b[i]) t += v[i];
  for (int i = 0; i < m; i++)
    if (v[n - 1 - i] < 0 && !b[n - 1 - i]) tt += v[n - 1 - i];
  cout << max(res + t, res + tt);
  return 0;
}
