open System

let getTwoInts (_: 'unit): int*int =
    let [|fst; sec|] = Console.ReadLine().Split(' ') |> Array.map Int32.Parse
    fst, sec

[<EntryPoint>]
let main _ =
    let n, m = getTwoInts()
    let gates = List.init m getTwoInts
    let lMax = List.map fst gates |> List.max
    let rMin = List.map snd gates |> List.min
    
    max 0 ((min rMin n) - lMax + 1)
    |> printfn "%d"
    
    0
