#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, up = 0, low = 0, temp = 0;
  cin >> n >> k;
  int i1[110], i2[110];
  for (i = 1; i <= n; i++) cin >> i2[i];
  for (i = 1; i <= n; ++i) {
    up = 0;
    low = 0;
    for (j = 1; j <= n; j++) i1[j] = i2[j];
    i1[i] = 0;
    for (j = k; i - j >= 1 || i + j <= n; j += k) {
      if (i - j >= 1) i1[i - j] = 0;
      if (i + j <= n) i1[i + j] = 0;
    }
    for (j = 1; j <= n; j++) {
      if (i1[j] == 1) up++;
      if (i1[j] == -1) low++;
    }
    if (abs(up - low) > temp) temp = abs(up - low);
  }
  cout << temp << endl;
  return 0;
}
