#include <bits/stdc++.h>
using namespace std;
int N, K, ans, v[110];
vector<int> num;
int main(int argc, char** argv) {
  scanf("%d%d", &N, &K);
  for (int i = (1); i <= (N); i++) scanf("%d", &v[i]);
  for (int i = (0); i <= (N); i++) {
    int cnt = 0;
    for (int j = 1; j <= N; j++) {
      bool ok = true;
      for (int k = -100; k <= 100; k++)
        if (j == (i + (k * K))) {
          ok = false;
          break;
        }
      if (ok) cnt += v[j];
    }
    ans = max(ans, abs(cnt));
  }
  printf("%d\n", ans);
  cerr << "\n\t\t\t\tAdson_S\n";
  ;
  return 0;
}
