lines = []
while line = $stdin.gets do
  lines << line.chomp.split(" ")
end

l = 0
r = 100000

lines.delete_at(0)

lines.each do |line|
  l = line[0].to_i if line[0].to_i > l
  r = line[1].to_i if line[1].to_i < r
end

p r - l + 1