#include <bits/stdc++.h>
using namespace std;
long long fastPow(long long b, long long p) {
  if (p == 0) return 1;
  long long st = fastPow(b, p / 2);
  st *= st;
  if (p % 2 == 1) {
    st *= b;
  }
  return st;
}
bool isPrime(long long n) {
  if (n < 2) return false;
  if (n % 2 == 0) return false;
  for (long long i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  long long test = 0;
  long long social = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == -1)
      social++;
    else
      test++;
  }
  long long res = 0;
  bool del[n];
  memset(del, true, sizeof del);
  for (long long i = 0; i < n; i++) {
    social = test = 0;
    for (long long j = i; j < n; j += k) {
      del[j] = false;
    }
    for (long long j = i; j >= 0; j -= k) {
      del[j] = false;
    }
    for (long long j = 0; j < n; j++) {
      if (del[j]) {
        if (arr[j] == -1)
          social++;
        else
          test++;
      }
    }
    res = max(res, abs(social - test));
    memset(del, true, sizeof del);
  }
  cout << res;
  return 0;
}
