"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nk = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nk[0], K = nk[1];
    let X = lines.shift().split(/\s/).map((v) => v - 0);
    if (N == 1) {
        console.log(Math.abs(X[0]));
        return;
    }
    let start = Math.abs(Math.min(...X));
    for (let i = 0; i < N; i++) X[i] += start;
   let abs = new Array(N - 1);
    for (let i = 0; i < abs.length; i++) {
        abs[i] = X[i + 1] - X[i];
    }
    for (let i = 1; i < abs.length; i++) {
        abs[i] = abs[i - 1] + abs[i];
    }
    let ans = {a:Number.MAX_SAFE_INTEGER, i:0};
    for (let i = 0; i < N - K; i++) {
        let d = abs[i + K - 1] - abs[i];
        let e = Number.MAX_SAFE_INTEGER;
        for (let j = 0; j < K - 1; j++) {
            let f = Math.abs(start - X[j]);
            if (e > f) e = f;
        }
        d += e;
        if (ans.a > d) ans = {a:d, i:i};
    }
    console.log(ans.a);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
