#include <bits/stdc++.h>
using namespace std;
int main() {
  int tabs[101];
  int n, k, b, aux, total_s = 0, total_e = 0;
  int aux_e, aux_s, max_abs;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> aux;
    tabs[i] = aux;
    total_s += aux == -1 ? 1 : 0;
    total_e += aux == 1 ? 1 : 0;
  }
  max_abs = -1;
  for (int b = 0; b < n; b++) {
    aux_e = total_e, aux_s = total_s;
    for (int i = -100; i < n; i++) {
      int c = b + i * k;
      if (c < n && c >= 0) {
        aux_e += tabs[c] == 1 ? -1 : 0;
        aux_s += tabs[c] == -1 ? -1 : 0;
      }
    }
    max_abs = max(max_abs, abs(aux_e - aux_s));
  }
  cout << max_abs;
  return 0;
}
