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

left = 1
right = N
M.times do
  l, r = gets.chomp.split(' ').map(&:to_i)
  left = [ left, l ].max
  right = [ right, r ].min
end

puts right >= left ? right - left + 1 : 0
