#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n + 2];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  long long maxi = 0;
  map<long long, long long> mp;
  for (long long i = 1; i < n; i++) {
    for (long long j = -n; j <= n; j++) {
      if ((i + (j * k) >= 1) && ((i + (j * k)) <= n)) {
        mp[i + (j * k)] = 1;
      }
    }
    long long on = 0, ze = 0;
    for (long long j = 1; j <= n; j++) {
      if (mp[j] == 0) {
        if (arr[j] == 1)
          on++;
        else
          ze++;
      }
    }
    maxi = max(maxi, abs(ze - on));
    for (long long j = -n; j <= n; j++) {
      if ((i + (j * k) >= 1) && ((i + (j * k)) <= n)) {
        mp[i + (j * k)] = 0;
      }
    }
  }
  cout << maxi << endl;
  return 0;
}
