let rec loop a p = function
  [] -> a | ((l,r)::xs) -> if p < l then loop (a+1) (r-1) xs else loop a p xs
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  Array.init m (fun _ -> Scanf.scanf " %d %d" (fun x y -> x,y)) |> Array.to_list
  |> List.sort (fun (a,b) (c,d) -> compare (b,a) (d,c)) |> loop 0 (-1)
  |> Printf.printf "%d\n"