import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

class Node(val data:Int) {
  var prev:Node = null
  var next:Node = null
}

class DList {
  var first = new Node(-1)
  var last = new Node(-1)
  first.next = last
  first.next.prev = first

  def insert(data:Int) = {
    var newNode = new Node(data)
    newNode.next = first.next
    if(first.next!=null) first.next.prev = newNode
    first.next = newNode
    newNode.prev = first
  }

  def search(data:Int) = {
    var node = first.next
    while(node != last && node.data != data) {
      node = node.next
    }
    node
  }

  def delete(node:Node):Unit = {
    if(node!=last) {
      node.prev.next = node.next
      node.next.prev = node.prev
    }
  }

  def delete(data:Int):Unit = delete(search(data))
  def deleteFirst() = delete(first.next)
  def deleteLast() = delete(last.prev)

  def print() = {
    val b = new ArrayBuffer[Int]
    var node = first.next
    while(node != last) {
      b += node.data
      node = node.next
    }
    println(b.toArray.mkString(" "))
  }
}

object Main {
  def main(args:Array[String]) = {
    val dlist = new DList()
    val n = readInt
    for(i<-1 to n) {
      val s = readLine.split(" ")
      if(s(0)=="insert") dlist.insert(s(1).toInt)
      else if(s(0)=="delete") dlist.delete(s(1).toInt)
      else if(s(0)=="deleteFirst") dlist.deleteFirst
      else if(s(0)=="deleteLast") dlist.deleteLast
    }
    dlist.print()
  }
}