import Control.Applicative
import Data.Array

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 = seisa arr m m len 1
        where
          (a,_) = arr ! len
          seisa arr m n len x
            | m == len    = arr // [(n,(fstarr n,x))]
            | fstarr (m+1) < fstarr m = seisa arr (m+1) n len hikaku
            | otherwise   = seisa arr (m+1) n len x
            where
              fstarr n = fst $ arr ! n
              sndarr n = snd $ arr ! n
              hikaku = max x ((sndarr (m+1))+1)