#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) { return x * x; }
long double sqrd(long double x) { return x * x; }
mt19937 Random((int)time(0));
long long rnd(long long x) { return Random() % x; }
const long long INF = (long long)1e9 + 282;
const long long MOD = (long long)1e9 + 7;
const long double PI = acosl(-1.0);
const int N = 110;
int arr[N];
void mane() {
  int n, k;
  cin >> n >> k;
  int sum = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  for (int i = 0; i < n; i++) {
    int res = sum;
    for (int j = i; j >= 0; j -= k) {
      res -= arr[j];
    }
    for (int j = i + k; j < n; j += k) {
      res -= arr[j];
    }
    ans = max(ans, abs(res));
  }
  cout << ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios_base::fixed, ios_base::floatfield);
  cout.precision(12);
  mane();
}
