#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
class {
 public:
  void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> f(n + 1);
    for (int i = 1; i <= n; i++) cin >> f[i];
    int ans = -MOD;
    for (int i = 1; i <= n; i++) {
      vector<bool> vis(n + 1);
      for (int j = -100; j <= 100; j++) {
        if (j * k + i >= 1 && j * k + i <= n) vis[j * k + i] = true;
      }
      int e = 0, s = 0;
      for (int j = 1; j <= n; j++) {
        if (vis[j]) continue;
        if (f[j] == 1)
          e++;
        else
          s++;
      }
      ans = max(ans, abs(s - e));
    }
    cout << ans;
  }
} NSPACE;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
