N = gets.chomp.to_i
LR = Array.new(N) { gets.chomp.split.map(&:to_i) }

Contest = Struct.new(:min, :max, :tasks) do
  def fun
    tasks.empty? ? 0 : (max - min).next
  end

  def clamp(new_min, new_max)
    self.class.new(
      new_min > min ? new_min : min,
      new_max < max ? new_max : max,
      [1]
    )
  end

  def add(new_min, new_max)
    self.min = new_min > min ? new_min : min
    self.max = new_max < max ? new_max : max
    self.tasks.push(new_min..new_max)
  end
end

a = Contest.new(0, 10 ** 9, [])
b = Contest.new(0, 10 ** 9, [])

LR.each do |min, max|
  add_to_a = a.clamp(min, max)
  add_to_b = b.clamp(min, max)

  if add_to_a.fun + b.fun >= a.fun + add_to_b.fun
    a.add(min, max)
  else
    b.add(min, max)
  end
end

puts a.fun + b.fun