exec :: [String] -> [String] -> [String]
exec l ("insert":x:_) = x:l
exec l ("delete":x:_) =
  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 o