#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[101];
  int E = 0, S = 0, e = 0, s = 0;
  a[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == 1)
      E += 1;
    else if (a[i] == -1)
      S += 1;
  }
  int max = 0;
  for (int b = 1; b <= n; ++b) {
    e = E, s = S;
    for (int i = (1 - b) / k; i <= (n - b) / k; ++i) {
      int c = b + k * i;
      if (c > 0 && c <= n && e >= 0 && s >= 0) {
        if (a[c] == 1) {
          a[c] == 0;
          e -= 1;
        } else if (a[c] == -1) {
          a[c] == 0;
          s -= 1;
        }
      }
    }
    int ans = abs(e - s);
    if (ans > max) max = ans;
  }
  cout << max;
  return 0;
}
