"use strict";
    
const absOfArray = array => {
    const N = array.length;
    const temp = [];
    
    for(let i=1; i<N; i++) {
        temp.push(Math.abs(array[i-1] - array[i]));
    }
    
    return temp.reduce((m,n)=>m+n);
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    const X = arg[1].split(" ").map(n=>parseInt(n));
    
    const minus = X.slice(0, K);
    const plus  = X.slice(-K);
    
    let newX;
    
    // ゼロに置かれている時
    if(X.filter(n=>n===0).length) {
        newX = minus.concat([0]).concat(plus);
    } else {
        newX = minus.concat(plus);
    }
    
    
    if(N <= K) {
        console.log(absOfArray(newX));
        return;
    }
    
    // マイナスしかない
    if(minus.filter(n=>n>0).length === K) {
        console.log(absOfArray(minus) + Math.abs(absOfArray(minus) - 0));
        return;
    }
    
    // プラスしかない
    if(plus.filter(n=>n<0).length === K) {
        console.log(absOfArray(plus) + Math.abs(absOfArray(plus) - 0));
        return;
    }
    
    let memo = absOfArray(newX.slice(0, K));
    let answer = memo;
    
    for(let i=1; i<N-K; i++) {
        let temp = memo - newX[i - 1];
        temp += newX[i];
        
        answer = Math.min(answer, memo);
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));