import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt()
  var list: ListBuffer[String] = ListBuffer()
  for (i <- 1 to n) {
    val o = StdIn.readLine().split(" ").toList
    list = o.head match {
      case "insert" => o.last +: list
      case "delete" => list - o.last
      case "deleteFirst" => list.tail
      case "deleteLast" => list.dropRight(1)
    }
  }
  println(list.mkString(" "))
}