import Data.List
import Control.Monad.State

insertDL :: Int -> State [Int] Int
insertDL n = state $ \xs -> (n, n:xs)

deleteDL :: Int -> State [Int] Int
deleteDL n = state $ \xs -> (n, delete n xs)

deleteFirst :: State [Int] Int
deleteFirst = state $ \xs -> (0, init xs)

deleteLast :: State [Int] Int
deleteLast = state $ \xs -> (0, tail xs)

main = do
  _ <- getLine
  lines <- fmap lines getContents
  let cmds = parse lines :: [(String, Int)]
  let result = foldM execCmd 0 cmds
  putStrLn $ concat . intersperse " " . map show . snd . runState result $ []

parse :: [String] -> [(String, Int)]
parse lines = map (\x -> case x of
                           [y] -> (y, -1)
                           [y, z] -> (y, read z)) cmds
              where cmds = map words lines

execCmd :: Int -> (String, Int) -> State [Int] Int
execCmd _ (cmd, n)
  | cmd == "insert"      = insertDL n
  | cmd == "delete"      = deleteDL n
  | cmd == "deleteFirst" = deleteFirst
  | otherwise            = deleteLast