#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2> &p) const {
    auto h1 = std::hash<T1>{}(p.first);
    auto h2 = std::hash<T2>{}(p.second);
    return h1 ^ h2;
  }
};
long long pw(long long te, long long tee) {
  if (tee == 0) return 1;
  long long res = pw(te, tee / 2);
  return (tee % 2 ? te * res * res : res * res);
}
long long n, k, a[MAXN], b[2];
void Read_input() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < 0)
      b[0]++;
    else
      b[1]++;
  }
}
void Solve() {
  long long ans = 0;
  for (long long i = 1; i <= k; i++) {
    long long t = 0, c[2] = {};
    for (long long j = i; j <= n; j += k)
      if (a[j] < 0)
        c[0]++;
      else
        c[1]++;
    t = abs(b[0] - c[0] - (b[1] - c[1]));
    ans = max(ans, t);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Read_input(), Solve();
  return 0;
}
