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 (process (M.empty) os) 

process _ [] = []
process q ([x]:os) = process (M.insertWith (+) (readInt x) 1 q) os
process q (_:os)
 | v > 1 = k : process (M.adjust pred k q) os
 | otherwise = k : process q' os
 where ((k,v),q') = M.deleteFindMax q