#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i, a, j, e = 0, s = 0, b;
  long long int arr[200];
  scanf("%lld%lld", &n, &k);
  for (long long int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    if (arr[i] == 1) {
      e++;
    } else {
      s++;
    }
  }
  long long int ans = 0;
  for (long long int b = 1; b <= 100; b++) {
    long long int e1 = e, s1 = s, sum;
    for (j = -100; j <= 100; j++) {
      i = b + (j * k);
      if (i > 0 && i <= n) {
        if (arr[i] == 1) {
          e1--;
        } else {
          s1--;
        }
      }
    }
    sum = abs(e1 - s1);
    ans = max(sum, ans);
  }
  cout << ans << endl;
}
