let [| N; K |] = stdin.ReadLine().Split() |> Array.map int

let h =
    [ for i in [ 0..N - 1 ] do
        yield (stdin.ReadLine() |> int) ]
    |> List.sort

let rec solver m i =
    if i = N - K + 1 then m
    elif m > h.[i + K - 1] - h.[i] then solver (h.[i + K - 1] - h.[i]) (i + 1)
    else solver m (i + 1)

solver h.[N - 1] 0 |> stdout.WriteLine
