#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MOD = 1000000000 + 7;
int arr[111];
int main() {
  int n, k;
  scanf("%d", &n), scanf("%d", &k);
  int cnt3 = 0, cnt4 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == -1)
      cnt3++;
    else
      cnt4++;
  }
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    int cnt1 = 0, cnt2 = 0;
    for (int j = i; j <= n; j += k) {
      if (arr[j] == -1)
        cnt1++;
      else
        cnt2++;
    }
    ans = max(ans, abs((cnt3 - cnt1) - (cnt4 - cnt2)));
  }
  cout << ans;
}
