#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int N, K;
  cin >> N >> K;
  int a[N];
  int maxi = 0;
  for (int i = (0); i < (N); ++i) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
  }
  if (maxi <= 0) {
    cout << 0 << endl;
    return 0;
  }
  int cnt = 0;
  bool flag = true;
  for (int i = (0); i < (N - K); ++i) {
    if (a[i] < 0 && flag)
      a[i] = 0;
    else if (a[i] > 0)
      flag = false;
  }
  flag = true;
  for (int i = (0); i < (N - K); ++i) {
    if (a[N - 1 - i] < 0 && flag)
      a[N - 1 - i] = 0;
    else if (a[N - 1 - i] > 0)
      flag = false;
  }
  for (int i = (0); i < (N); ++i) {
    if (a[i] <= 0) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (a[i] <= 0) {
      if (cnt == K - 1) {
        for (int j = i; j > i - K + 1; j--) {
          a[j] = 0;
        }
      } else if (cnt > K - 1) {
        a[i] = 0;
      }
    }
  }
  int res = 0;
  for (int i = (0); i < (N); ++i) {
    res += a[i];
  }
  cout << max(res, 0) << endl;
  return 0;
}
