import Control.Applicative
import Data.Array
import Data.List

main = do
  len <- (read :: String -> Int) <$> getLine
  xs <- map (read :: String -> Int) . lines <$> getContents
  let arr = listArray (1,len) (zip xs [0,0..])
  print $ ans $syorinaiyou arr len
 
ans arr = maximum $ map snd $ elems $ arr
 
syorinaiyou :: Array Int (Int, Int) -> Int -> Array Int (Int, Int)
syorinaiyou arr len = foldl' keisan arr (reverse [1..len])
    where
      keisan :: Array Int (Int, Int) -> Int -> Array Int (Int, Int)
      keisan arr m
        | m == len = arr // [(m,(a,1))]
        | otherwise    = fst $ foldl' seisa' (arr,1) [m..(len+1)]
        where
          (a,_) = arr ! len
          seisa' (arr,x) t
            | t > len  = (koushin,x)
            | fstarr m < fstarr t = (arr,hikaku)
            | otherwise          = (arr,x)
            where
              fstarr r = fst $ arr ! r
              sndarr r = snd $ arr ! r
              hikaku = max x ((sndarr t)+1)
              koushin = arr // [(m,(fstarr m,x))]