let [| total; usedCount |] = stdin.ReadLine().Split() |> Array.map int
let candles = stdin.ReadLine().Split() |> Array.map int

let distance sortedCandles =
    let head = sortedCandles |> Seq.head 
    let last = sortedCandles |> Seq.last
    min (head |> abs) (last |> abs)
    |> (+) (last - head |> abs)

// 配列のコピーにコストがかかっているので遅延リストを用いて配列をコピーさせないテスト

candles
|> Array.ofSeq
|> Seq.windowed usedCount
|> Seq.map distance
|> Seq.min
|> stdout.WriteLine