{-# OPTIONS_GHC -O2 -fexcess-precision #-}
import Control.Applicative
import Data.Array.Unboxed
import Data.List (foldl')
import Data.Foldable (maximumBy)
import Data.Ord (comparing)
import qualified Data.Set as Set

main = do
  len <- (read :: String -> Int) <$> getLine
  xs <- map (read :: String -> Int) . lines <$> getContents
  let arr = listArray (1,len) xs :: UArray Int Int
  print $ snd $ maximumBy (comparing snd) $ syorinaiyou arr len

syorinaiyou arr len =
  foldl' (keisan arr) Set.empty (reverse [1..len])
    where
      keisan arr set n
        | Set.null set =  Set.insert ((arr ! n),1) set
        | otherwise  = seisa arr set n
        where
          seisa arr set n
            | Set.null set' = Set.insert (hikaku_moto,1) set
            | otherwise  = Set.insert (hikaku_moto, oldLIS + 1) set2
            where
              hikaku_moto = arr ! n
              (set1, set')   = Set.split (hikaku_moto + 1 , 0) set
              (old,oldLIS) = maximumBy (comparing snd) set'
              set2 = Set.union set1 (snd (Set.split (old,oldLIS-1) set'))