import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- replicateM n getInt
    let ans = length $ foldl' solve [] as
    print ans

solve ss a | null t = a : ss
           | otherwise = (init t) ++ (a : d)
    where (t,d) = span (< a) ss