import Control.Monad
import Data.List (sortBy)
import Data.Function (on)

main = do
  li <- getLine
  let n = read li
  as <- forM [1..n] (\_ -> do
    li <- getLine
    return $ read li
    )
  let ans = compute as
  print ans

compute :: [Int] -> Int
compute = length . loop . initial

initial as = [ [(a,a)] | a <- as ]

loop [x] = x
loop xs = loop (zipWith1 connect xs)

zipWith1 f (x:y:xs) = f x y : zipWith1 f xs
zipWith1 f xs = xs

connect abs cds = merge abs1 cds1 where
  abs1 = sortBy (compare `on` (negate.snd)) abs
  cds1 = sortBy (compare `on` (negate.fst)) cds

merge ((a,b):abs) cds1@((c,d):cds)
  | b < c = (a,d) : merge abs cds
  | True  = (a,b) : merge abs cds1
merge abs [] = abs
merge [] cds = cds