#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, K;
  cin >> N >> K;
  ll A = 0;
  if (N == K) {
    K = 0;
    for (int i = 0; i < N; i++) {
      cin >> K;
      A += (ll)K;
    }
    cout << max(A, 0LL) << endl;
    return 0;
  }
  vector<pair<ll, ll>> B(N, {0, 0});
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (i) {
      if (i < K) {
        B[i].first = max({B[i - 1].first, B[i - 1].second, B[i].second + A, A});
        B[i].second = max(B[i - 1].second + A, A);
      } else {
        B[i].first = max({B[i - 1].first, B[i - 1].second, B[i - 1].second + A,
                          B[i - K].first + A});
        B[i].second = max(B[i - 1].second + A, B[i - K].first + A);
      }
    } else {
      B[i] = {max(A, 0LL), A};
    }
  }
  cout << B[N - 1].first << endl;
}
