#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int n, k, i, j, c1, c2;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int maxn = -99999;
  for (i = 0; i < k; i++) {
    c1 = 0;
    c2 = 0;
    for (j = 0; j < n; j++) {
      if (j % k != i) {
        if (a[j] == 1)
          c1++;
        else
          c2++;
      }
    }
    maxn = max(maxn, abs(c1 - c2));
  }
  cout << maxn << endl;
  return 0;
}
