head = gets
h = head.split(/ /)
min = 1
max = h[0].to_i
while line = gets
  l = line.split(/ /)
  if min < l[0].to_i
    min = l[0].to_i
  end
  if max > l[1].to_i
    max = l[1].to_i
  end
end

ans = max - min + 1
p ans