
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val num = StdIn.readInt
    var list = List.empty[Int]

    for (i <- 1 to num) {
      val query = StdIn.readLine().split(" ")
      val value = if (query.length == 2) query(1).toInt else 0
      query(0) match {
        case "insert" => list = List(value) ++ list
        case "delete" => list = list.filterNot(_ == value)
        case "deleteFirst" => list = list.tail
        case "deleteLast" => list = list.init
      }
    }
    println(list.mkString(" "))
  }
}