import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    int x1 = A.count(1).to!int;
    int x2 = A.count(-1).to!int;

    int ans = 0;
    foreach (i; 0..N) {
        int cnt1 = 0, cnt2 = 0;
        foreach (j; 0..N) {
            if (abs(j - i) % K == 0) {
                if (A[j] == 1) cnt1 += 1;
                else cnt2 += 1;
            }
        }
        ans = max(ans, abs((x1 - cnt1) - (x2 - cnt2)));
   }

    ans.writeln;
}
