import Data.List
import Data.Maybe
import Control.Applicative
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

readInt = fst . fromJust . B.readInt

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

pq q = reverse . fst . foldl' process ([],q)

process (acc,q) [x] = (acc, M.insertWith (+) (readInt 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