#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
long long ksm(long long a, long long b, long long m) {
  long long sum = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) sum = (sum * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return sum;
}
int a[N], in[N];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int b = 0, c = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] == -1)
      b++;
    else
      c++;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!in[i]) {
      in[i] = 1;
      int b1 = 0, c1 = 0;
      for (int j = i; j <= n; j += k) {
        in[j] = 1;
        if (a[j] == -1)
          b1++;
        else
          c1++;
      }
      for (int j = i - k; j >= 1; j -= k) {
        in[j] = 1;
        if (a[j] == -1)
          b1++;
        else
          c1++;
      }
      ans = max(abs((c - c1) - (b - b1)), ans);
    }
  }
  printf("%d\n", ans);
  return 0;
}
