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

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

[ 0..N - K ]
|> List.map (fun i -> h.[i + K - 1] - h.[i])
|> List.min
|> stdout.WriteLine
