#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
const int inf = (INT_MAX >> 3);
int n, k;
int A[111];
int ret() {
  int i, j, b, ans = 0;
  for (b = 1; b <= n; b++) {
    int got = 0;
    for (j = 1; j <= n; j++) {
      if ((j - b) % k != 0) {
        got += A[j];
      }
    }
    ans = max(ans, abs(got));
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  int i, j;
  for (i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  int ans = ret();
  printf("%d\n", ans);
  return 0;
}
