#include <bits/stdc++.h>
using namespace std;
int n, k, bal, mbal;
int arr[105];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    bal += arr[i];
  }
  mbal = -53;
  for (int i = 0; i < k; i++) {
    int bali = bal;
    for (int j = i; j < n; j += k) {
      bali -= arr[j];
    }
    mbal = max(mbal, abs(bali));
  }
  cout << mbal << endl;
  return 0;
}
