#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, k;
int a[200];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  int e = 0, s = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1)
      e++;
    else
      s++;
  }
  int ee = e, ss = s;
  int ans = -1;
  for (int b = 1; b <= k; b++) {
    ee = e;
    ss = s;
    for (int i = 0; b + i * k <= n; i++) {
      int c = b + i * k;
      if (a[c] == 1)
        ee--;
      else
        ss--;
    }
    ans = max(ans, abs(ee - ss));
  }
  printf("%d\n", ans);
  return 0;
}
