let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let hs = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun h -> h in
  Array.sort compare hs;
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@ 
  Array.init (n - k + 1) @@ fun i -> hs.(i + k - 1) - hs.(i)
