import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.List (foldl')

main = do
  len <- (read :: String -> Int) <$> getLine
  xs <- map (read :: String -> Int) . lines <$> getContents
  let arr = Map.fromList $ zip [1..len] (zip xs [0,0..])
  print $ ans $ syorinaiyou arr len

ans arr = maximum $ map (snd . snd)  $ Map.toList $ arr

syorinaiyou arr len = foldl' keisan arr (reverse [1..len])
    where
      keisan arr m
        | m == len = Map.insert m (a,1) arr
        | 1==1     = fst $ foldl' seisa' (arr,1) [m..(len+1)]
        where
          (a,_) = arr Map.! len
          seisa' (arr,x) t
            | t > len  = (koushin,x)
            | fstarr m < fstarr t = (arr,hikaku)
            | otherwise          = (arr,x)
            where
              fstarr r = fst $ arr Map.! r
              sndarr r = snd $ arr Map.! r
              hikaku = max x ((sndarr t)+1)
              koushin = Map.insert m (fstarr m,x) arr