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

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

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