#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int &i : V) cin >> i;
  int ret = -1000000000;
  for (int b = 0; b < N; b++) {
    vector<int> C = V;
    int s = -b / K;
    int p = 0;
    int m = 0;
    for (int i = s; b + i * K < N; i++) C[b + i * K] = 0;
    for (int i = 0; i < N; i++) {
      p += C[i];
      m -= C[i];
    }
    ret = max(ret, max(p, m));
  }
  cout << ret << endl;
  return 0;
}
