import Control.Monad
import Data.List

main :: IO ()
main = do
  l1 <- getLine
  let n = read l1
  lr_ <- map (map read . words) <$> sequence (replicate n getLine)
  let lr = sort lr_ :: [[Integer]]
      ([a1, a2], l, [b1, b2]) = (head lr, tail (init lr), last lr)
      (l1, l') = span (\[x, y] -> y < b1) l
      (l2, l3) = span (\[x, y] -> x <= a2) l
      (l21, l22) = span (\[x, y] -> if a1 < x && y < a2 && x < b1 && b2 < y then False else x - a1 <= b2 - y) l2
      [x1, y1] = foldl (\[x, y] [x', y'] -> [max x x', min y y']) [a1, a2] $ l1 ++ l21
      [x2, y2] = foldl (\[x, y] [x', y'] -> [max x x', min y y']) [b1, b2] $ l22 ++ l3
  -- print [a1, a2]
  -- print [b1, b2]
  -- print l1
  -- print l21
  -- print l22
  -- print l3
  print $ y1 - x1 + y2 - x2 + 2