class DoublyLinkedList:
    def __init__(self):
        self.first = Node(-1)
        self.first.setNext(Node(-1))

    def insert(self, value):
        newNode = Node(value)
        newNode.setNext(self.first.getNext())
        newNode.setPrev(self.first)
        self.first.getNext().setPrev(newNode)
        self.first.setNext(newNode)

    def delete(self, value):
        self.first.delete(value)

    def deleteFirst(self):
        if self.first.getNext().getValue() != -1:
            self.first.setNext(self.first.getNext().getNext())

    def deleteLast(self):
        self.first.deleteLast()

    def printAll(self):
        if self.first.getNext().getValue() != -1:
            self.first.getNext().printAll()

class Node:
    def __init__(self, value):
        self.value = value
        self.prev = None
        self.next = None

    def getValue(self):
        return self.value

    def setValue(self, value):
        self.value = value

    def getNext(self):
        return self.next

    def setNext(self, next):
        self.next = next

    def getPrev(self):
        return self.prev

    def setPrev(self, prev):
        self.prev = prev

    def delete(self, value):
        if self.next.getValue() == value:
            self.next = self.next.getNext()
            self.next.setPrev(self)
        else:
            self.next.delete(value)

    def deleteLast(self):
        if self.next.value == -1:
            self.prev.setNext(self.next)
            self.next.setPrev(self.prev)
        else:
            self.next.deleteLast()

    def printAll(self):
        if self.next.getValue() != -1:
            print self.value,
            self.next.printAll()
        else:
            print self.value

if __name__ == "__main__":
    dll = DoublyLinkedList()

    N = input()
    for i in range(N):
        raw = raw_input().split()
        com = raw[0]
        if len(raw) > 1:
            value = int(raw[1])
        if com == "insert":
            dll.insert(value)
        elif com == "delete":
            dll.delete(value)
        elif com == "deleteFirst":
            dll.deleteFirst()
        else:
            dll.deleteLast()
    dll.printAll()

### FIXED CODE ###

import sys

class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value

if __name__ == "__main__":
    dll = DoublyLinkedList()
    lines = sys.stdin.readlines()
    lines.pop(0)
    for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
    dll.printAll()