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)

// TLE対策で、明らかに対象外である端のwindowedを切り捨ててみる
let near0I = 
    candles |> Seq.tryFindIndex (fun x -> x>=0) |> function None -> candles.Length-1 | Some(v) -> v

candles.[
    (if near0I - usedCount < 0 then 0 else near0I - usedCount) .. 
        (if near0I + usedCount > candles.Length - 1 then candles.Length - 1 else near0I + usedCount)]
|> Seq.windowed usedCount
|> Seq.map distance
|> Seq.min
|> stdout.WriteLine

