#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, countt = 0, counts = 0, maxi = 0;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == -1)
      counts++;
    else
      countt++;
  }
  for (long long int b = 0; b < k; b++) {
    long long int ts = counts, tt = countt;
    for (long long int j = 0; b + (j * k) + 1 <= n; j++) {
      if (a[b + (j * k) + 1] == -1)
        ts--;
      else
        tt--;
    }
    maxi = max(maxi, abs(ts - tt));
  }
  cout << maxi << endl;
  return 0;
}
