#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[111];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int e = 0, second = 0;
    for (int j = 0; j < n; j++) {
      if (abs(i - j) % k == 0) continue;
      if (a[j] == 1)
        e++;
      else
        second++;
    }
    ans = max(ans, abs(e - second));
  }
  cout << ans << endl;
  return 0;
}
