#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, s = 0, e = 0, ans = 0;
  cin >> n >> k;
  int ar[200] = {0};
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == -1)
      s++;
    else
      e++;
  }
  for (int i = 0; i < k; i++) {
    int ts = s, te = e;
    for (int j = i; j < n; j += k) {
      if (ar[j] == 1)
        --te;
      else
        --ts;
    }
    ans = max(ans, abs(te - ts));
  }
  cout << ans << endl;
  return 0;
}
