#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt(time(0));
const int MAXN = 123;
int nums[MAXN], tmp[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }
  int ret = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      tmp[j] = nums[j];
    }
    int tot = n;
    for (int j = i; j <= n; j += k) {
      tmp[j] = 0;
      tot--;
    }
    int cur = 0;
    for (int j = 1; j <= n; j++) {
      if (tmp[j] == 1) cur++;
    }
    ret = max(ret, abs(tot - 2 * cur));
  }
  cout << ret << endl;
  return 0;
}
