#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n, cou, ans, arr[N], k, e0, s0, e, s;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == -1)
      s++;
    else
      e++;
  }
  for (int i = 0; i < k; i++) {
    e0 = e;
    s0 = s;
    for (int j = 0; j < n; j++) {
      if ((j + 1) % k == i) {
        if (arr[j] == -1)
          s0--;
        else
          e0--;
      }
    }
    ans = max(ans, abs(e0 - s0));
  }
  cout << ans;
}
