#include <bits/stdc++.h>
using namespace std;
int main() {
  if (0) {
    freopen("CP.inp", "r", stdin);
    freopen("CP.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  int a[100];
  int n, k, tmpe, tmps, res = 0, e = 0, s = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1)
      ++e;
    else
      ++s;
  }
  for (int l = 0; l < k; ++l) {
    tmpe = e;
    tmps = s;
    for (int j = l; j < n; j += k) {
      (a[j] == 1 ? --tmpe : --tmps);
    }
    res = max(res, abs(tmpe - tmps));
  }
  cout << res << '\n';
  return 0;
}
