#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[150], br[150], cr[150], n, i, j, k, l = 0, m, max;
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (i = 1; i <= k; i++) {
    int count = 0, countt = 0;
    for (j = 1; j <= n; j++) {
      br[j] = ar[j];
    }
    for (j = i; j <= n; j += k) {
      br[j] = 0;
    }
    for (m = 1; m <= n; m++) {
      if (br[m] == 1) {
        count++;
      } else if (br[m] == -1) {
        countt++;
      }
    }
    cr[l] = abs(count - countt);
    l++;
  }
  max = cr[0];
  for (i = 1; i < l; i++) {
    if (max < cr[i]) {
      max = cr[i];
    }
  }
  cout << max << endl;
  return 0;
}
