import           Data.List                      ( foldl' )
import           Control.Monad                  ( replicateM )

type SpritPt = (Int, Int)

main :: IO ()
main = do
    _ : n : _ <- map read . words <$> getLine
    ls        <-
        map ((\(a : b : _) -> (a, b)) . map read . words)
            <$> replicateM n getLine :: IO [SpritPt]
    print . length . foldl' append [] $ ls

merge :: SpritPt -> SpritPt -> Maybe SpritPt
merge (a, b) (c, d) =
    let x = max a c
        y = min b d
    in  if x < y then Just (x, y) else Nothing


append :: [SpritPt] -> SpritPt -> [SpritPt]
append []       a = [a]
append (x : xs) a = case merge a x of
    Just m  -> append xs m
    Nothing -> x : append xs a
