import qualified Data.Map as Map
import Data.List

main = getLine >> getContents >>= putStrLn.unwords.map show.Map.elems.foldl' (\m s -> parse s $ m) Map.empty.lines

parse :: String -> Map.Map Int Int -> Map.Map Int Int
parse "deleteFirst" m = Map.deleteMin m
parse "deleteLast"  m = Map.deleteMax m  
parse str           m = let [order, x] = words str
                         in case order of
                            "insert" -> let n = if m == Map.empty then 0 else (flip (-) 1).fst $ Map.findMin m 
                                        in Map.insert n (read x) m
                            "delete" -> defaultMap.delete (read x) $ Map.elems m

defaultMap :: [a] -> Map.Map Int a
defaultMap = Map.fromList.zipWith (,) [0..]