#include <bits/stdc++.h>
using namespace std;
int N, K;
long long A[100010];
long long B[100010];
long long f(long long *X) {
  if (N == K) {
    long long ret = 0;
    for (int i = 0; i < N; i++) ret += X[i];
    return max(0LL, ret);
  }
  long long t = 0, g = 0;
  for (int i = 0; i < N; i++) {
    g += X[i];
    if (i < K - 1)
      t = max(0LL, g);
    else
      t = max(0LL, t + max(X[i], 0LL));
  }
  return t;
}
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[N - 1 - i] = A[i];
  }
  cout << max(f(A), f(B)) << "\n";
  return 0;
}
