import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Control.Applicative
import Control.Monad
import Data.IORef

doublyList :: [(String, Int)] -> IO [Int]
doublyList cmds = do
  vec <- UM.new (2 * 10^6)
  front <- newIORef (10^6 :: Int)
  rear  <- newIORef (10^6 + 1 :: Int)
  forM_ cmds $ \cmd -> do
    f cmd vec front rear
  f <- readIORef front
  r <- readIORef rear
  ans <- U.freeze $ UM.slice (f + 1) (r - f - 1) vec
  return (U.toList $ U.filter (>= 0) ans)
    where
      f ("insert", n) vec front rear = do
        f <- readIORef front
        UM.write vec f n
        modifyIORef front (subtract 1)
      f ("delete", n) vec front rear = do
        f <- readIORef front
        r <- readIORef rear
        forM_ [f .. r] $ \i -> do
          v <- UM.read vec i
          when (v == n) $ do
            UM.write vec i (-1)
            return ()
      f ("deleteFirst", _) vec front rear = modifyIORef front (+ 1)
      f ("deleteLast", _)  vec front rear = modifyIORef rear (subtract 1)

main :: IO ()
main = do
  n <- readLn
  xs <- map (toTuple . words) <$> replicateM n getLine
  ys <- doublyList xs
  putStrLn $ unwords $ map show ys
    where
      toTuple [s]    = (s, 0)
      toTuple [s, n] = (s, read n)

