open System

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

let rec getMaxMin lMax rMin = function
 | [] -> failwith "Undefined"
 | [ _ ] ->
    let [| l; r |] = getIntLine()
    max l lMax, min r rMin
 | _ :: xs ->
    let [| l; r |] = getIntLine()
    getMaxMin (max l lMax) (min r rMin) xs

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

    0

