local n, m  = io.read("*n", "*n")
local l, r = 1, n
local mmi, mma = math.min, math.max
for i = 1, m do
  local a, b = io.read("*n", "*n")
  l = mma(l, a)
  r = mmi(r, b)
end
print(mma(0, r - l + 1))
