#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, c, n, k, *a;
  cin >> n >> k;
  a = new int[n];
  for (i = 0; i < n; ++i) cin >> a[i];
  int ans = 0, cur, sum = 0;
  for (i = 0; i < n; ++i) sum += a[i];
  for (i = 0; i < k; ++i) {
    cur = 0;
    c = i;
    while (c < n) {
      cur += a[c];
      c += k;
    }
    cur = abs(sum - cur);
    if (ans < cur) ans = cur;
  }
  cout << ans << endl;
  return 0;
}
