#include <bits/stdc++.h>
using namespace std;
inline void boost() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
}
const long long maxn = 1e5 + 123;
const long long inf = 1e9 + 123;
const long long mod = 1e9 + 7;
const double infm = 1e-9;
const double pi = acos(-1);
int a[maxn];
bool used[maxn];
int main() {
  boost();
  int n, k;
  cin >> n >> k;
  int p = 0, m = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (abs(j - i) % k == 0) {
        used[j] = 1;
      }
    }
    int sum = 0, sum1 = 0;
    for (int j = 1; j <= n; j++) {
      if (used[j] == 0) {
        if (a[j] == 1) {
          sum++;
        } else {
          sum1++;
        }
      }
      used[j] = 0;
    }
    mx = max(mx, abs(sum - sum1));
  }
  cout << mx;
  return 0;
}
