exec :: [Int] -> [String] -> [Int]
exec l ("insert":x:_) = (read x):l
exec l ("delete":x:_) =
  let x' = read x :: Int
  in
    if elem x' l
    then ( takeWhile (/= x') l ) ++ (drop 1 $ dropWhile (/= x') l)
    else l
exec l ("deleteFirst":_) = tail l
exec l ("deleteLast":_)  = init l

main = do
  n <- getLine
  c <- getContents
  let i = map words $ lines c
      o = foldl exec [] i
  putStrLn $ unwords $ map show o  