import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM
import Control.Applicative
import Control.Monad
import Data.IORef
import Text.Printf
import Data.List

type Cmd = (String, Int)

doublyLinkedList :: [Cmd] -> [Int]
doublyLinkedList cmds = loop [] cmds
  where
    loop xs [] = xs
    loop xs ((c, x) : cmd)
      | c == "insert" = loop (x : xs) cmd
      | c == "delete" = loop (delete' x xs) cmd
      | c == "deleteFirst" = loop (tail xs) cmd
      | c == "deleteLast"  = loop (init xs) cmd

    delete' _ [] = []
    delete' a (x : xs)
      | a == x = xs
      | otherwise = x : delete' a xs

main :: IO ()
main = do
  n  <- readLn
  xs <- map (f . words) <$> replicateM n getLine
  putStrLn $ unwords $ map show $ doublyLinkedList xs
    where
      f [a]    = (a, 0)
      f [a, b] = (a, read b)

