#include <bits/stdc++.h>
using namespace std;
int tabs[110];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> tabs[i];
  int mx = 0;
  for (int b = 0; b < n; ++b) {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      if (i % k != b % k) sum += tabs[i];
    }
    mx = max(mx, abs(sum));
  }
  cout << mx << '\n';
  return 0;
}
