#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int e_full = 0;
  int s_full = 0;
  vector<int> tabtype(n);
  for (int i = 0; i < n; i++) {
    cin >> tabtype[i];
    e_full += max(tabtype[i], 0);
    s_full += -min(tabtype[i], 0);
  }
  int maxval = 0;
  for (int b = 1; b <= k; b++) {
    int e = 0, s = 0;
    for (int i = 0; i <= n; i++) {
      int c = b + i * k;
      if (c > n) break;
      e += max(tabtype[c - 1], 0);
      s += -min(tabtype[c - 1], 0);
    }
    maxval = max(abs((e_full - e) - (s_full - s)), maxval);
  }
  cout << maxval << endl;
}
