#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, max = -101, te, Info = 0, Chat = 0, f = 0;
  cin >> n >> k;
  int a[n], A[n];
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    A[i] = a[i];
  }
  for (int i = 0; i <= k - 1; i++) {
    te = i;
    while (te <= n - 1) {
      A[te] = 0;
      te += k;
    }
    for (int j = 0; j <= n - 1; j++) {
      if (A[j] == 1)
        Info++;
      else if (A[j] == -1)
        Chat++;
    }
    f = abs(Info - Chat);
    if (f > max) max = f;
    for (int I = 0; I <= n - 1; I++) {
      A[I] = a[I];
    }
    Info = 0;
    Chat = 0;
  }
  cout << max;
  return 0;
}
