#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int maxi = -1;
  int A[1000];
  int tot = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    tot += A[i];
  }
  for (int b = 0; b <= 100; b++) {
    int cur = 0;
    for (int i = -100; i <= 100; i++) {
      int ind = b + i * K;
      if (ind >= 0 && ind < N) cur += A[ind];
    }
    cur = tot - cur;
    if (cur < 0) cur *= -1;
    if (cur > maxi) maxi = cur;
  }
  cout << maxi;
  return 0;
}
