#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, x, s = 0;
  vector<int> a;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
    s += x;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int e = 0, o = 0;
    for (int j = 0; j < n; j++) {
      if (abs(j - i) % k == 0) continue;
      if (a[j] == 1)
        e++;
      else
        o++;
    }
    ans = max(ans, abs(e - o));
  }
  cout << ans << endl;
  return 0;
}
