#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  vector<long long> sum_pos_l(N + 1), sum_pos_r(N + 1), sum_all(N + 1);
  for (int i = 0; i < (int)(N); i++) {
    sum_pos_l[i + 1] = sum_pos_l[i] + max(A[i], 0LL);
    sum_pos_r[i + 1] = sum_pos_r[i] + max(A[N - i - 1], 0LL);
    sum_all[i + 1] = sum_all[i] + A[i];
  }
  long long ans = -INFLL;
  for (int i = 0; i < (int)(N - K + 1); i++) {
    int l = i, r = K - i;
    long long tmp =
        sum_pos_l[l] + sum_pos_r[r] + max(0LL, sum_all[N - r] - sum_all[l]);
    ans = max(ans, tmp);
    cerr << "("
         << "i"
         << ", "
         << "tmp"
         << ") = (" << i << ", " << tmp << ")" << endl;
  }
  cout << ans << endl;
}
