#include <bits/stdc++.h>
using namespace std;
void solve(void);
int main() {
  { solve(); }
  return 0;
}
void solve() {
  int n, k, mx = 0, sum, b;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (b = 0; b < n; b++) {
    sum = 0;
    for (int i = 0; i < n; i++) {
      if (i % k != b % k) sum += a[i];
    }
    mx = max(mx, abs(sum));
  }
  cout << mx << endl;
}
