#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<pair<int, int>, int> &a,
               const pair<pair<int, int>, int> &b) {
  if (a.first != b.first)
    return a.first.first < b.first.first;
  else
    return (a.first.second < b.first.second);
}
bool sortbys(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first != b.first)
    return (a.first < b.first);
  else
    return a.second < b.second;
}
long long moduloMultiplication(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    long long p = (2 * (a % mod)) % mod;
    a = (p) % mod;
    b >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n + 1];
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    long long p = 0, c = 0;
    for (int j = 1; j <= n; j++) {
      if ((j - i) % k != 0) {
        if (a[j] == 1) p++;
        if (a[j] == -1) c++;
      }
    }
    s = max(s, abs(p - c));
  }
  cout << s << "\n";
  ;
}
