#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
const int M = 4e6 + 7;
const int lim = 3e5;
const int mod = 1e9 + 7;
const double inf = 0x3f3f3f3f;
const double PI = acos(-1);
int a[N];
int main() {
  int n, k, aa = 0, bb = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < 0)
      bb++;
    else
      aa++;
  }
  int mx = 0;
  for (int i = 1; i <= k; i++) {
    int tpa = 0, tpb = 0;
    for (int j = i; j <= n; j += k) {
      if (a[j] == 1)
        tpa++;
      else
        tpb++;
    }
    mx = max(mx, abs(aa - tpa - (bb - tpb)));
  }
  printf("%d\n", mx);
  return 0;
}
