#include <bits/stdc++.h>
int a[1009];
int b[1009];
int main() {
  int n, k, Max, cnttest, cntplay, ans;
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      b[i] = a[i];
    }
    Max = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j += k) b[j] = 0;
      for (int j = i; j >= 0; j -= k) b[j] = 0;
      cnttest = 0;
      for (int j = 0; j < n; j++) {
        if (b[j] == 1) cnttest++;
      }
      cntplay = 0;
      for (int j = 0; j < n; j++) {
        if (b[j] == -1) cntplay++;
      }
      ans = cnttest - cntplay > cntplay - cnttest ? cnttest - cntplay
                                                  : cntplay - cnttest;
      if (ans > Max) Max = ans;
      for (int j = 0; j < n; j++) b[j] = a[j];
    }
    printf("%d\n", Max);
  }
  return 0;
}
