### BUGGY CODE ###

class Node():
    def __init__(self,value,prv,nxt):
        self.value = value
        self.prv = prv
        self.nxt = nxt

class LinkedList():

    def __init__(self,head,tail):
        self.head = head
        self.tail = tail

    def insert(self,value):
        if self.head == None:
            self.head = Node(value,None,None)
            self.tail = self.head
        else:
            node = Node(value,None,self.head)
            if self.head.nxt == self.tail: #when only one node exists.
                self.head.prv = node
                self.head = node
            else:
                self.head.prv = node
                self.head = node

    def delete(self,value):
        check_node = self.head
        while not check_node == None:
            if check_node.value == value:
                if check_node == self.tail:
                    self.deleteLast()
                elif check_node == self.head:
                    self.head = check_node.nxt
                    check_node.nxt.prv = None
                else:
                    check_node.prv.nxt = check_node.nxt
                    check_node.nxt.prv = check_node.prv
                break
            check_node = check_node.nxt

    def deleteFirst(self):
        if self.head.nxt == None:
            self.head == None
        else:
            self.head = self.head.nxt

    def deleteLast(self):
        if self.head == self.tail:
            self.head = None
            self.tail = None
        else:
            self.tail.prv.nxt = None
            self.tail = self.tail.prv

n = int(input())
linkedList = LinkedList(None,None)

def getAnswer(linkedList):
    answer = []
    check = linkedList.head
    while True:
        answer.append(check.value)
        if check.nxt == None:
            break
        else:
            check = check.nxt

    print(" ".join(map(str,answer)))

for _ in range(n):
    line = input()
    #print(line)
    if not line == "deleteFirst" and not line == "deleteLast":
        command = line.split(" ")[0]
        value = int(line.split(" ")[1])
    else:
        command = line

    if command == "insert":
        linkedList.insert(value)
    elif command == "delete":
        linkedList.delete(value)
    elif command == "deleteFirst":
        linkedList.deleteFirst()
    elif command == "deleteLast":
        linkedList.deleteLast()

    #getAnswer(linkedList)

getAnswer(linkedList)



### FIXED CODE ###

class D_Linked_List:
    class Node:
        def __init__(self, key, next = None, prev = None):
            self.next = next
            self.prev = prev
            self.key = key
 
    def __init__(self):
        self.nil = D_Linked_List.Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil
 
    def insert(self, key):
        node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
        self.nil.next.prev = node_x
        self.nil.next = node_x
 
    def _listSearch(self, key):
        cur_node = self.nil.next
        while (cur_node != self.nil) and (cur_node.key != key):
            cur_node = cur_node.next
        return cur_node
 
    def _deleteNode(self, node):
        if node == self.nil:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev
 
    def deleteFirst(self):
        self._deleteNode(self.nil.next)
 
    def deleteLast(self):
        self._deleteNode(self.nil.prev)
 
    def deleteKey(self, key):
        node = self._listSearch(key)
        self._deleteNode(node)
 
    def show_keys(self):
        cur_node = self.nil.next
        keys = []
        while cur_node != self.nil:
            keys.append(cur_node.key)
            cur_node = cur_node.next
        print(' '.join(keys))
 
 
import sys
 
d_ll = D_Linked_List()
 
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d_ll.insert(x)
    elif 'deleteFirst' in i:
        d_ll.deleteFirst()
    elif 'deleteLast' in i:
        d_ll.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d_ll.deleteKey(x)
    else:
        pass
 
d_ll.show_keys()