import Data.List
import Control.Applicative
import qualified Data.IntMap.Strict as M

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

pq :: M.IntMap Int -> [[String]] -> [Int]
pq q = reverse . fst . foldl' process ([],q)

process (acc,q) [x] = (acc, M.insertWith (+) (read x) 1 q)
process (acc,q) _
 | v > 1 = (k:acc, M.adjust pred k q)
 | otherwise = (k:acc, M.delete k q)
 where (k,v) = M.findMax q