open Scanf
open Printf

let pair a b = a, b

let rec scan_list = function
  | 0 -> []
  | n -> scanf "%d %d\n" (fun a b -> (a,b) :: scan_list (n-1))

let rec f count amin = function
  | [] -> count
  | (a,b) :: xs -> if a <= amin 
    then f count amin xs
    else f (count + 1) (b-1) xs

let () = let _,m = scanf "%d %d\n" pair in
  let lst = scan_list m in
  printf "%d\n" (f 0 0 @@ List.sort (fun (a1,b1) (a2,b2) -> compare (b1,a1) (b2,a2)) lst)