#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, b, maxy = INT_MIN;
  cin >> n >> k;
  vector<int> arr(n);
  vector<int> arr1(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    b = i;
    vector<int> arrx = arr;
    for (int j = b; j < n; j += k) {
      arrx[j] = 0;
    }
    for (int j = b; j >= 0; j -= k) {
      arrx[j] = 0;
    }
    int e = 0, s = 0;
    for (int p = 0; p < n; p++) {
      if (arrx[p] == 1)
        e++;
      else if (arrx[p] == -1)
        s++;
    }
    arr1[i] = abs(e - s);
  }
  for (int q = 0; q < n; q++) {
    if (arr1[q] > maxy) {
      maxy = arr1[q];
    }
  }
  cout << maxy;
}
