import Control.Monad
import Control.Monad.ST
import Debug.Trace
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
-- import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed.Mutable as UMV

main = do
    n <- head . unfoldr BS.readInt <$> BS.getLine
    a <- UV.fromList . map (head . unfoldr BS.readInt) <$> replicateM n BS.getLine
    print $ UV.length $ UV.foldl' sub5 UV.empty a

sub5 :: UV.Vector (Int, Int) -> Int -> UV.Vector (Int, Int)
sub5 ls n | UV.length m1 == 0 = runST $ do
                ls_ <- UV.thaw ls
                ls_ <- UMV.grow ls_ 1
                UMV.write ls_ (UMV.length ls_ - 1) (UMV.length ls_ - 1, n)
                UV.freeze ls_
          | otherwise = runST $ do
                ls_ <- UV.thaw ls
                UMV.write ls_ (fst m2) (fst m2, n)
                UV.freeze ls_

    where m1 = UV.filter (\(_, y) -> y < n) ls
          m2 = UV.maximum m1
