#include <bits/stdc++.h>
using namespace std;
long long int binaryExponentiation(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return binaryExponentiation(x * x, n / 2);
  else
    return x * binaryExponentiation(x * x, (n - 1) / 2);
}
long long int modularExponentiation(long long int x, long long int n,
                                    long long int M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  else
    return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(long long x) {
  bool prime = (x >= 2);
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, maxi = -1, c, d, e;
  cin >> n >> k;
  vector<int> v(n);
  for (long long int i = 1; i < n + 1; i++) {
    cin >> v[i - 1];
  }
  for (long long int i = 1; i < k + 1; i++) {
    e = i;
    c = 0;
    d = 0;
    for (long long int j = 0; j < n; j++) {
      if ((j + 1) == e) {
        e += k;
      } else {
        if (v[j] == 1) {
          c++;
        } else
          d++;
      }
    }
    maxi = max(maxi, abs(c - d));
  }
  cout << maxi;
  return 0;
}
