#include <bits/stdc++.h>
using namespace std;
int a[105], a2[105], n;
int getabs() {
  int e = 0, s = 0, i;
  for (i = 1; i <= n; i++) {
    if (a[i] == 1) e++;
    if (a[i] == -1) s++;
  }
  return abs(e - s);
}
int main() {
  int k, i, c, b, ans = 0;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a2[i] = a[i];
  }
  for (b = 1; b <= n; b++) {
    i = 1;
    while (b + i * k > 0) i--;
    for (i++; b + i * k <= n; i++) {
      a[b + i * k] = 0;
    }
    ans = getabs() > ans ? getabs() : ans;
    for (i = 1; i <= n; i++) a[i] = a2[i];
  }
  printf("%d\n", ans);
  return 0;
}
