import Control.Applicative
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S

main = do
  _ <- getLine
  xs <- readInts <$> B.getContents
  let ans = length (lis xs)
  print ans

lis :: Ord a => [a] -> [a]
lis = S.toList . snd . foldl go (S.empty, S.empty)
  where
    go (acc, acc0) x = case S.lookupGT x acc of
      Nothing -> let acc1 = S.insert x acc in (acc1, acc1)
      Just g -> (S.insert x (S.delete g acc), acc0)

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.words
