#include <bits/stdc++.h>
using namespace std;
vector<long long> sum(100001);
int n, k, x[100001];
long long Sum(int i) {
  if (i + k > n) return -(1LL << 50);
  return sum[i + k] - sum[i];
}
long long Sum(int l, int r) {
  if (r > n) return -(1LL << 50);
  return sum[r + 1] - sum[l];
}
long long mem[100001], used[100001];
long long dfs(int idx) {
  if (idx + k > n) return 0;
  if (used[idx]++) return mem[idx];
  long long res = x[idx] > 0 ? x[idx] + dfs(idx + 1) : dfs(idx + 1);
  res = max(res, Sum(idx) + dfs(idx + k));
  for (int i = 0; i < k; i++) {
    if (idx + k + i + 1 > n) break;
    if (Sum(idx + k, idx + k + i) < 0) continue;
    res = max(res, Sum(idx + k, idx + k + i) + dfs(idx + k + i + 1));
  }
  return mem[idx] = res;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> x[i], sum[i + 1] += x[i] + sum[i];
  cout << dfs(0) << endl;
  return 0;
}
