#include <bits/stdc++.h>
using namespace std;
int modul(int a, int b) {
  if (a - b < 0) return b - a;
  return a - b;
}
int main() {
  int n, k, st, et, s, e, d, v[103], j, m, stm, etm;
  cin >> n >> k;
  st = et = 0;
  d = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    if (v[i] == 1)
      et++;
    else
      st++;
  }
  stm = etm = 0;
  for (int i = 1; i <= k; i++) {
    s = st;
    e = et;
    j = i;
    while (j <= n) {
      if (v[j] == 1)
        e--;
      else
        s--;
      j += k;
    }
    m = modul(s, e);
    if (m > d) {
      stm = s;
      etm = e;
      d = m;
    }
  }
  cout << d;
  return 0;
}
