import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  (lr0 : lr1 : lrs) <- sequence . replicate n $ unsafeListToTuple . map unsafeSignedDecimal . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    pDef | g lr0 < g lr1 = (lr1, lr0)
         | otherwise = (lr0, lr1)
    pMax = h pDef lrs
    (lr0', lr1') = foldl step pMax $ lrs
      where
        step (lr0, lr1) lr | g lr0 - g lr0' < g lr1 - g lr1' = (lr0', lr1)
                           | otherwise = (lr0, lr1')
          where
            lr0' = f lr0 lr
            lr1' = f lr1 lr
  print $ g lr0' + g lr1'

h :: ((Int, Int), (Int, Int)) -> [(Int, Int)] -> ((Int, Int), (Int, Int))
h p@(lr0, lr1) (lr : lrs) | g lr > g lr0 = h (lr, lr0) lrs
                          | g lr > g lr1 = h (lr0, lr) lrs
                          | otherwise = h p lrs
h p _ = p

g :: (Int, Int) -> Int
g (l, r) = max 0 (r - l + 1)

f :: (Int, Int) -> (Int, Int) -> (Int, Int)
f (l, r) (l', r') = (max l l', min r r')

unsafeListToTuple :: [Int] -> (Int, Int)
unsafeListToTuple (x : y : _) = (x, y)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
