#include <bits/stdc++.h>
using namespace std;
int k, n, a[102], s;
int ans;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], s += a[i];
  for (int i = 1; i <= k; ++i) {
    int cur = s;
    for (int j = i; j <= n; j += k) cur -= a[j];
    ans = max(ans, abs(cur));
  }
  cout << ans << "\n";
}
