#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  std::vector<int> tabs(n);
  for (int i = 0; i < n; i++) scanf("%d", &tabs[i]);
  std::vector<int> res;
  for (int i = 0; i < k; i++) {
    std::vector<int> a(tabs);
    for (int j = i; j < n; j += k) a[j] = 0;
    int e = std::count(a.begin(), a.end(), 1);
    int s = std::count(a.begin(), a.end(), -1);
    res.push_back(std::max(std::abs(e - s), std::abs(s - e)));
  }
  printf("%d\n", *std::max_element(res.begin(), res.end()));
  return 0;
}
