import Data.List
import Data.Maybe
import Data.Array.IO
import qualified Data.ByteString.Lazy.Char8 as C

newA :: [[C.ByteString]] -> IO ()
newA xs = do
  ary <- newArray (0,2000000) 0
  solve ary xs 0 0

toI :: C.ByteString -> Int
toI = fst . fromJust . C.readInt

printArray :: IOUArray Int Int -> Int -> Int -> IO ()
printArray ary fs ls
  | fs == ls = return ()
  | otherwise = do
      x <- readArray ary fs
      if (x == (-1)) then
        printArray ary (fs+1) ls
        else do
        putStr $ show x
        printArray' ary (fs+1) ls

printArray' :: IOUArray Int Int -> Int -> Int -> IO ()
printArray' ary fs ls
  | fs == ls = return ()
  | otherwise = do
      x <- readArray ary fs
      if (x == (-1)) then
        printArray' ary (fs+1) ls
        else do
        putStr " "
        putStr $ show x
        printArray' ary (fs+1) ls

solve :: IOUArray Int Int -> [[C.ByteString]] -> Int -> Int -> IO ()
solve ary [] fs ls = printArray ary fs ls
solve ary all@([a]:xs) fs ls
  | C.length a > 6 && C.index a 6 == 'F' = do
      x <- readArray ary (ls-1)
      if (x == (-1)) then
        solve ary all fs (ls-1)
        else solve ary xs fs (ls-1)
  | C.length a > 6 && C.index a 6 == 'L' = do
      x <- readArray ary fs
      if (x == (-1)) then
        solve ary all (fs+1) ls
        else solve ary xs (fs+1) ls
solve ary ([a,b]:xs) fs ls
  | C.index a 0 == 'i' = do
      writeArray ary ls (toI b)
      solve ary xs fs (ls+1)
solve ary ([_,a]:xs) fs ls = do
  search ary (toI a) fs ls
  solve ary xs fs ls
    where search ary i f l
            | f == l = return ()
            | otherwise = do
                x <- readArray ary (l-1)
                if (x == i) then
                  writeArray ary (l-1) (-1)
                  else search ary i f (l-1)

main = getLine >> C.getContents >>= newA . map C.words . C.lines
