{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
readIntegers = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine :: IO [Integer]
readVInts = map (fst . fromJust . B.readInt) . B.lines <$> B.getContents

main :: IO ()
main = do
  n <- readLn :: IO Int
  -- as <- replicateM n $ readLn :: IO [Int]
  as <- readVInts
  print $ solve'' n as

solve'' n (a:as) = length $ foldl' go [a] as
  where
    go bs a
      | a <= mn = insert a bs
      | otherwise = insert a $ deleteUpperBound (< a) bs
      where
        mn = head bs   

deleteUpperBound :: (Ord a) => (a -> Bool) -> [a] -> [a]
deleteUpperBound pred (a:b:as)
  | pred a && not (pred b) = b:as
  | not (pred a) = a:b:as
  | otherwise = a:(deleteUpperBound pred (b:as))
deleteUpperBound pred (a:[]) = if pred a then [] else [a]
deleteUpperBound pred [] = []
