function Main(input) {
    input = input.split("\n");
    tmp = input[0].split(" ");
    numtmp = input[1].split(" ");
    var n = parseInt(tmp[0], 10);
    var m = parseInt(tmp[1], 10);
    nums = [];
    for (i = 0; i < numtmp.length; i++) {
        nums[i] = parseInt(numtmp[i], 10);
    }
    base = nums.slice();
    var p1 = base.indexOf(1);
    var min = "NULL";

    for (i = 0; i < m; i++) {
        nums = base.slice();
        var pt = p1 + i;
        var cnt = 0;
        cnt = s1(nums, pt, m, cnt);
        pt = p1 + i;
        cnt = s2(nums, pt, m, cnt);
        if (min == "NULL" || min > cnt) min = cnt;
    }
    for (i = 0; i < m; i++) {
        nums = base.slice();
        var pt = p1 - i;
        var cnt = 0;
        cnt = s2(nums, pt, m, cnt);
        pt = p1 - i;
        cnt = s1(nums, pt, m, cnt);
        if (min == "NULL" || min > cnt) min = cnt;
    }
    console.log('%d', min);
}

function s1(n, p, m, c) {
    while (n[0] != 1) {
        for (j = 0; j < m; j++) {
            n[p] = 1;
            p--;
            if (p <= 0) break;
        }
        c++;
    }
    return c;
}

function s2(n, p, m, c) {
    while (n[n.length - 1] != 1) {
        for (j = 0; j < m; j++) {
            n[p] = 1;
            p++;
            if (p >= n.length - 1) break;
        }
        c++;
    }
    return c;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));