#include <bits/stdc++.h>
using namespace std;
int n, k, x[101];
int resi(int a) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    double c;
    c = 1. * ((1. * abs(i - a)) / k);
    if (floor(c) != c) {
      sum += x[i];
    }
  }
  return abs(sum);
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> x[i];
  int mah = 0;
  for (int i = 1; i <= k; i++) mah = max(mah, resi(i));
  cout << mah;
  return 0;
}
