#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e3 + 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int a[n + 1], e = 0, s = 0, mx = 0;
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  for (long long i = 1; i < k + 1; i++) {
    e = 0;
    s = 0;
    for (long long j = 1; j < n + 1; j++) {
      if ((j - i) % k != 0) {
        if (a[j] > 0)
          e++;
        else
          s++;
      }
    }
    mx = max(abs(e - s), mx);
  }
  cout << mx;
  return 0;
}
