n, m = gets.chomp.split(' ').map(&:to_i)

gates = []

max_l = -1
min_r = -1

m.times do |i|
  l, r = gets.chomp.split(' ').map(&:to_i)
  if max_l < 0 || max_l < l
    max_l = l
  end
  if min_r < 0 || min_r > r
    min_r = r
  end
  gates << [l,r]
end

cleard_num = 0

num = min_r - max_l + 1
if num > 0
  print "#{num}"
else
  print "0"
end