#include <bits/stdc++.h>
using namespace std;
int n, k, a[105], ans, test, net;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == 1)
      ++test;
    else
      ++net;
  }
  for (int b = 1; b <= k; ++b) {
    int ts = 0, nt = 0;
    for (int j = 0; b + k * j <= n; ++j) {
      if (a[b + k * j] == 1)
        ++ts;
      else
        ++nt;
    }
    ans = max(ans, abs((test - ts) - (net - nt)));
  }
  printf("%d\n", ans);
  return 0;
}
