#include <bits/stdc++.h>
using namespace std;
int const INF = (int)1e9 + 1e3;
long long const INFL = (long long)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<long long> ll_distr;
long long rnd(long long a, long long b) {
  return ll_distr(tw) % (b - a + 1) + a;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> inp;
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    inp.push_back(num);
  }
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    int sum = accumulate(inp.begin(), inp.end(), 0);
    for (int j = i; j < n; j += k) {
      sum -= inp[j];
    }
    ans = max(ans, abs(sum));
  }
  cout << ans << "\n";
}
int main() {
  cout << setprecision(15) << fixed;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_count = 1;
  for (int test = 1; test <= test_count; ++test) {
    solve();
  }
}
