let bas = Scanf.scanf "%d %d" @@ fun _ m -> Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> b, a
let _ = Array.(sort compare bas; fold_left (fun (c, k) (b, a) -> if a <= k then c, k else c + 1, b - 1) (0, 0) bas) |> fst |> Printf.printf "%d\n"