#include <bits/stdc++.h>
int arr[100];
int arr2[100];
using namespace std;
int main() {
  long int n, k, ck = 0, np = 0, hp = 1, i = 0, ph = 0, temp;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int b = 0; b < k; b++) {
    for (int c = b; c < n; c += k) {
      arr2[c] = arr[c];
      arr[c] = 0;
    }
    for (int j = 0; j < n; j++) np = np + arr[j];
    hp = max(hp, abs(np));
    for (int c = b; c < n; c += k) arr[c] = arr2[c];
    np = 0;
  }
  cout << hp << endl;
  return 0;
}
