import Data.List
import Control.Applicative
import qualified Data.Set as S

main = do
 os <- map (tail . words) . init . lines <$> getContents
 mapM_ print (pq (S.empty) os) 

pq :: S.Set (Int,Int) -> [[String]] -> [Int]
pq q = reverse . fst . snd . foldl' process (0,([],q))

process (i,(acc,q)) [x] = (succ i, (acc, S.insert ((read x),i) q))
process (i,(acc,q)) _ = let ((vmax,_),q') = S.deleteFindMax q in (i, (vmax:acc, q'))