#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100001], n, k;
  int sum = 0;
  vector<int> plusp;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= 0) {
      plusp.push_back(i);
    };
  }
  if (n == k) {
    int sum1 = 0;
    for (int i = 0; i < n; i++) sum1 += a[i];
    sum = max(sum1, 0);
  } else if ((plusp[1] - plusp[0] > k) ||
             (plusp[plusp.size() - 2] - plusp[plusp.size() - 1] > k)) {
    for (int i = 0; i < plusp.size(); i++) sum += a[plusp[i]];
  } else {
    int frontsum = 0, endsum = 0;
    int sum1 = 0, sum2 = 0;
    for (int i = plusp[0]; i < plusp[0] + k; i++) frontsum += a[i];
    for (int i = plusp[plusp.size() - 1]; i > plusp[plusp.size() - 1] - k; i--)
      endsum += a[i];
    for (int i = 0; i < n - k; i++) {
      if (a[i] > 0) sum1 += a[i];
    }
    for (int i = n - k - 1; i >= 0; i--) {
      if (a[i] > 0) sum2 += a[i];
    }
    sum = max(sum1 + max(frontsum, 0), sum2 + max(endsum, 0));
  }
  cout << sum << endl;
  return 0;
}
