#include <bits/stdc++.h>
using namespace std;
void soln() {
  long long int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  int maxm = INT_MIN;
  for (int i = 1; i <= n; i++) {
    int b[n + 1];
    for (int j = 1; j <= n; j++) b[j] = a[j];
    int p = (1 - i) / k;
    int q = (n - i) / k;
    for (int j = p; j <= q; j++) {
      int e = i + (j * k);
      b[e] = 0;
    }
    int count0 = 0, count1 = 0;
    for (int j = 1; j <= n; j++) {
      if (b[j] == -1)
        count0++;
      else if (b[j] == 1)
        count1++;
    }
    maxm = maxm > abs(count0 - count1) ? maxm : abs(count0 - count1);
  }
  cout << maxm << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    soln();
  }
}
