#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[109];
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  int one = 0;
  int minus_one = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      one++;
    else
      minus_one++;
  }
  int ans = -1;
  for (int i = 0; i < k; i++) {
    int f1 = one;
    int f2 = minus_one;
    for (int j = i; j < n; j += k) {
      if (a[j] == 1) {
        f1--;
      } else {
        f2--;
      }
    }
    ans = max(ans, abs(f1 - f2));
  }
  cout << ans;
  return 0;
}
