#include <bits/stdc++.h>
using namespace std;
const int sz = 102;
int main() {
  int n, k, arr[sz], e, s, mx = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  for (int b = 0; b < k; b++) {
    e = 0;
    s = 0;
    for (int i = 0; i < n; i++) {
      if ((i - b + k) % k == 0) continue;
      if (arr[i] == 1)
        e++;
      else
        s++;
    }
    mx = max(mx, abs(s - e));
  }
  printf("%d\n", mx);
  return 0;
}
