Scanf.scanf "%d %d" (fun n k ->
    let h = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare h;

    let rec loop i acc =
        if i + k > n then acc else
            loop (i + 1) (min acc (h.(i + k - 1) - h.(i)))
    in
    loop 0 max_int |> Printf.printf "%d\n"
)