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 = (1..n).to_a
m.times { |i| ans = ans & (l[i - 1]..r[i - 1]).to_a }

puts ans.size