#include <bits/stdc++.h>
using namespace std;
int main() {
  int vis[105];
  int term[105];
  int n, k;
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) {
      cin >> vis[i];
      term[i] = vis[i];
    }
    int maxs = -1;
    for (int b = 1; b <= n; b++) {
      int c;
      for (int i = (1 - b) / k; i <= (n - b) / k; i++) {
        c = b + i * k;
        term[c] = 0;
      }
      int text = 0, so = 0;
      for (int i = 1; i <= n; i++) {
        if (term[i] == 1)
          text++;
        else if (term[i] == -1)
          so++;
        term[i] = vis[i];
      }
      maxs = max(maxs, max(text - so, so - text));
    }
    cout << maxs << endl;
  }
}
