N, M = gets.split.map(&:to_i)
l, r = 0
nl, nr = 0
M.times do |i|
  l, r = gets.split.map(&:to_i)
  if i == 0
    nl, nr = l, r
  end
  if r < nl or nr < l
    puts 0
    exit
  end
  if nl < l
    nl = l
  end
  if r < nr
    nr = r
  end
  # puts "i=#{i} #{nl} #{nr}"
end

puts nr-nl+1