open System

let getIntLine() = Console.ReadLine().Split(' ') |> Array.map Int32.Parse

let getMaxMin (l: 'a list): int*int =
    let mutable lMax, rMin = 0, Int32.MaxValue
    for _ in l do
        let [|l; r |] = getIntLine()
        if l > lMax then lMax <- l
        if r < rMin then rMin <- r
    lMax, rMin

[<EntryPoint>]
let main _ =
    let [| n; m |] = getIntLine()
    let lMax, rMin = getMaxMin [ 1..m ]
    let res =
        if lMax <= rMin && lMax <= n then
            (min rMin n) - lMax + 1
        else
            0
    printfn "%d" res

    0
