local N, M = io.read("n", "n")
local lmax = 0
local rmin = math.floor(10^5)
for i=1, M do
    local l, r = io.read("n", "n")
    lmax = math.max(lmax, l)
    rmin = math.min(rmin, r)
end
local n = rmin - lmax + 1
if n < 0 then n = 0 end
print(n)
