#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int vis[maxn];
int main() {
  int k, n;
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 1; i <= k; i++) {
      memset(vis, 0, sizeof(vis));
      for (int j = i; j <= n; j += k) {
        vis[j] = 1;
      }
      int cnt1 = 0, cnt2 = 0;
      for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
          if (a[i] == 1)
            cnt1++;
          else
            cnt2++;
        }
      }
      ans = max(abs(cnt2 - cnt1), ans);
    }
    cout << ans << endl;
  }
}
