#include <bits/stdc++.h>
const int NN = 110;
int x, y, ans, n, k, a[NN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    x = y = 0;
    for (int j = 1; j <= n; j++)
      if ((j - i) % k != 0) {
        if (a[j] == 1)
          x++;
        else
          y++;
      }
    if (abs(x - y) > ans) ans = abs(x - y);
  }
  printf("%d", ans);
  return 0;
}
