#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[202000];
int main() {
  long long sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) sum += a[i];
  }
  for (int i = n; i < 2 * n; i++) {
    a[i] = a[i - n];
  }
  long long sum2 = 0, maxx = 0;
  for (int i = 0; i < k; i++) {
    if (a[i] < 0) sum2 += a[i];
  }
  maxx = max(maxx, sum + sum2);
  for (int i = k; i < n * 2; i++) {
    if (a[i] < 0) sum2 += a[i];
    if (a[i - k] < 0) sum2 -= a[i - k];
    maxx = max(maxx, sum + sum2);
  }
  cout << maxx;
}
