#include <bits/stdc++.h>
using namespace std;
long long int powm(long long int base, long long int exp) {
  long long int ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % 1000000007;
    exp >>= 1, base = (base * base) % 1000000007;
  }
  return ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  long long int n, k, ans = 0;
  cin >> n >> k;
  long long int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int b = 1; b <= n; b++) {
      long long int closed[n + 1];
      for (int l = 1; l <= n; l++) closed[l] = -1;
      long long int c;
      for (int j = 0; j <= n; j++) {
        c = b + j * k;
        if (c >= 1 && c <= n) closed[c] = 0;
      }
      for (int j = 1; j <= n; j++) {
        c = b - j * k;
        if (c >= 1 && c <= n) closed[c] = 0;
      }
      long long int e = 0, s = 0;
      for (int j = 1; j <= n; j++) {
        if (closed[j] == -1 && a[j] == -1)
          s += 1;
        else if (closed[j] == -1 && a[j] == 1)
          e += 1;
      }
      ans = max(ans, abs(e - s));
    }
  }
  cout << ans << endl;
}
