#include <bits/stdc++.h>
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LONG_MAX;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> ar(n);
  for (auto &i : ar) cin >> i;
  int ans = 0;
  for (int b = 0; b < n; ++b) {
    vector<int> used(n, 0);
    for (int i = -200; i <= 200; ++i) {
      int c = b + i * k;
      if (c >= 0 && c < n) {
        used[c] = 1;
      }
    }
    int e = 0, s = 0;
    for (int i = 0; i < n; ++i) {
      if (used[i]) continue;
      if (ar[i] == 1) {
        ++e;
      } else
        ++s;
    }
    ans = max(ans, abs(e - s));
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  if (false)
    cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC
         << " sec" << endl;
}
