n, m = gets.split.map(&:to_i)
l = []
r = []
m.times do
  tmp = gets.split.map(&:to_i)
  l.push tmp[0]
  r.push tmp[1]
end

ans = []
if m > 1
  tmp = (l[0]..r[0]).to_a
  m.times { |i| tmp = tmp & (l[i]..r[i]).to_a }
  ans = tmp
else
  ans = (l[0]..r[0]).to_a
end

puts ans.size