#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - k; i++) {
    if (a[i] > 0) {
      ans += a[i];
    }
  }
  ll sum = ans;
  ll tmp = 0;
  for (int i = n - k; i < n; i++) {
    tmp += a[i];
  }
  ans = max(ans, ans + tmp);
  for (int i = 1; i < k; i++) {
    sum += a[n - i];
    if (a[n - k + 1 - i] > 0) sum -= a[n - k + 1 - i];
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
