n, m = gets.split.map(&:to_i)
a = m.times.map { gets.split.map(&:to_i) }

arrs = []
a.each do |l,r|
  arrs << [*l..r]
end

if m == 1
  ans = arrs[0]
  puts ans.length
else
  ans = arrs[0]
  (1..arrs.length-1).each do |i|
    ans = ans & arrs[i]
  end
  puts ans.length
end