#include <bits/stdc++.h>
using namespace std;
int arr[2005];
int n, cnt1, cnt, k, c, c1, maxv;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cnt1 = 0;
  cnt = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 1) {
      cnt1++;
    } else {
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    c1 = 0;
    c = 0;
    for (int j = 0; i + j * k < n; j++) {
      if (arr[i + j * k] == 1) {
        c1++;
      } else {
        c++;
      }
    }
    for (int j = -1; i + j * k < n && i + j * k >= 0; j--) {
      if (arr[i + j * k] == 1) {
        c1++;
      } else {
        c++;
      }
    }
    if (abs(cnt1 - c1 - cnt + c) > maxv) {
      maxv = abs(cnt1 - c1 - cnt + c);
    }
  }
  cout << maxv;
  return 0;
}
