#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n];
  bool color[n][2];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - k + 1; i++) {
    if (a[i] > 0)
      color[i][0] = true;
    else
      color[i][0] = false;
    if (i == (n - k))
      for (int j = 1; j < k + 1; j++) color[i + j][0] = color[i][0];
  }
  for (int i = n - 1; i >= k - 1; i--) {
    if (a[i] > 0)
      color[i][1] = true;
    else
      color[i][1] = false;
    if (i == k - 1)
      for (int j = 0; j < k - 1; j++) color[j][1] = color[i][1];
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (color[i][0] || color[i][1]) sum += a[i];
  }
  cout << sum << endl;
  return 0;
}
