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
    func cmd vec front rear

  f <- readIORef front
  r <- readIORef rear
  ans <- U.freeze $ UM.slice (f + 1) (r - f - 1) vec
  return (U.toList ans)
    where
      func ("insert", n) vec front rear = do
        f <- readIORef front
        UM.write vec f n
        modifyIORef front (subtract 1)
      func ("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
            forM_ [i - 1, i - 2 .. f] $ \j -> do
              v2 <- UM.read vec j
              UM.write vec (j + 1) v2
            modifyIORef front (+ 1)
      func ("deleteFirst", _) vec front rear = do
        modifyIORef front (+ 1)
      func ("deleteLast", _)  vec front rear = do
        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)

