N,M = gets.chomp.split.map(&:to_i)

from = 1
to = N

M.times do
  l, r = gets.chomp.split.map(&:to_i)
  from = l if l > from
  to = r if r < to
end

ans = to - from + 1
ans = 0 if (to - from + 1) < 0
puts ans
