import Data.List.Split
import Data.List
import Control.Monad

main = do
    a <- getContents
    let aa = splitOn "\n" a
    let b = tail $ init aa

    -- foldl' (+) 0 [1,2,3] => 6
    let aaa = foldl' od [] b
    let bbb = map (\x -> if x == -1 then "" else (show x)++ " ") aaa

    putStrLn $ init $ concat bbb
    return ()

od l s = me l o v
    where
        --(o:v1) = splitOn " " s
        (o:v1) = splitOn " " s
        vvv = if (length v1) == 0 then "-1" else head v1
        v = read vvv :: Int

me :: [Int] -> String -> Int -> [Int]
me l "insert" b      = [b] ++ l
--me l "delete" b      = concatMap (\x -> if x == b then [] else [x]) l
me l "delete" b      = delfst [] l b
me l "deleteFirst" b = if (head l) == -1 then (me (tail l) "deleteFirst" b) else tail l
me l "deleteLast" b  = if (last l) == -1 then (me (init l) "deleteLast" b) else init l

delfst lt [] v = lt
delfst lt (x: xs) v = if x == v then lt ++ xs else delfst (lt ++ [x]) xs v

