[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;m] = reads int
    let lrs = List.map (fun _ -> reads int |> fun [l;r] -> (l, r)) [1..m]
    let a = Array.create (n + 2) 0

    for (l, r) in lrs do
        a.[l] <- a.[l] + 1
        a.[r + 1] <- a.[r + 1] - 1

    Array.scan (+) 0 a
    |> Array.filter ((=) m)
    |> Array.length
    |> printfn "%i"

    0