n, m = gets.split.map(&:to_i)
lmin = 1
rmax = n
for i in 1..m do
  l, r = gets.split.map(&:to_i)
  lmin = l if lmin < l
  rmax = r if rmax > r
end
if lmin > rmax
  res = 0
else
  res = rmax - lmin + 1
end
puts res
