import Control.Monad
import Control.Applicative
import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- replicateM n $ do
    (x:y) <- words <$> getLine
    if null y
      then return (x, -1)
      else let (y':_) = y in return (x, read y')
  putStrLn $ unwords $ map show $ solve ss [] 

solve :: [(String, Int)] -> [Int] -> [Int]
solve [] ns = ns
solve ((c, n):ss) ns
  | c == "insert" = solve ss (n:ns)
  | c == "delete" = solve ss $ delete n ns
  | c == "deleteFirst" = solve ss (tail ns)
  | c == "deleteLast" = solve ss (init ns)
  | otherwise = error ""