parseint(x) = parse(Int, x)
parseintmap(x::Array{SubString{String},1}) = map(parseint, x)

function main()
    n, m = readline() |> split |> parseintmap
    l = 1
    r = 10^5
    for _ in 1:m
        ll, rr = readline() |> split |> parseintmap
        l = max(l, ll)
        r = min(r, rr)
    end
    println(r - l + 1)
end

main()