#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ans = INT_MIN, i, j, e, s, temp;
  cin >> n >> k;
  vector<int> b(n + 1), a(n + 1);
  for (i = 1; i <= n; ++i) cin >> b[i];
  for (i = 1; i <= k; ++i) {
    e = 0;
    s = 0;
    for (j = 1; j <= n; ++j) a[j] = b[j];
    for (j = i; j <= n; j += k) {
      a[j] = 0;
    }
    for (j = 1; j <= n; ++j) {
      if (a[j] == 1)
        e++;
      else if (a[j] == -1)
        s++;
    }
    temp = fabs(e - s);
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}
