#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int a[105];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]]++;
  }
  int maxn = -1;
  for (int j = 0; j <= n; j++) {
    int l = mp[1], r = mp[-1];
    for (int i = 1; i <= n; i++) {
      if (abs(i - j) % k == 0) {
        if (a[i] == -1)
          r--;
        else
          l--;
      }
    }
    maxn = max(maxn, abs(l - r));
  }
  printf("%d\n", maxn);
}
