local mab, mce, mfl, msq, mmi, mma = math.abs, math.ceil, math.floor, math.sqrt, math.min, math.max
local ior = io.input()
local n, m = ior:read("*n", "*n")
local left, right = ior:read("*n", "*n")
for i = 2, m do
  local x, y = ior:read("*n", "*n")
  left, right = mma(left, x), mmi(right, y)
end
if left <= right then
  print(right - left + 1)
else
  print(0)
end
