#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7;
int main() {
  int n, k;
  cin >> n >> k;
  int mx = -1;
  int ar[n + 2];
  int pos, neg;
  pos = neg = 0;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    if (ar[i] == 1)
      pos++;
    else
      neg++;
  }
  for (int i = 1; i <= n; i++) {
    int cntp = pos, cntneg = neg;
    for (int j = -100; j <= 100; j++) {
      if ((i + k * j >= 1) && (i + j * k) <= n) {
        if (ar[i + k * j] == 1)
          cntp--;
        else
          cntneg--;
      }
    }
    mx = max(mx, abs(cntp - cntneg));
  }
  cout << mx << "\n";
  return 0;
}
