open System

let rec calc i req = match i, req with
    | _, [] -> 0
    | i, [|a; b|] :: rs ->
        if i < a
        then 1 + calc (b-1) rs
        else calc i rs
 
let [|n; m|] = stdin.ReadLine().Split() |> Array.map int
let req =
    [ for _ in [1..m] -> stdin.ReadLine().Split() |> Array.map int ]
    |> List.sortBy (fun [|_; b|] -> b)

printfn "%d" <| calc 0 req
 