#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 4;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int max = 0;
  for (int i = 0; i < n; i++) {
    int arr[n];
    for (int i = 0; i < n; i++) arr[i] = a[i];
    for (int j = i; j < n; j += k) arr[j] = 0;
    for (int j = i; j >= 0; j -= k) arr[j] = 0;
    int p = 0, s = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == -1)
        s++;
      else if (arr[i] == 1)
        p++;
    }
    if (s > p)
      s -= p;
    else
      s = p - s;
    if (s > max) max = s;
  }
  printf("%d", max);
  return 0;
}
