### BUGGY CODE ###

class Node():
    def __init__(self,value,front_node,back_node):
        self.value = value
        self.front_node = front_node
        self.back_node = back_node

def insert(value,first_node):
    if first_node == None:
        new_node = Node(value, None, None)
    else:
        new_node = Node(value, None, first_node)
        first_node.front_node = new_node
    first_node = new_node
    return first_node

def delete(chk,first_node):
    flag = True
    next_node = first_node
    while flag:
        if next_node.value == chk:
            flag = False
            if next_node.back_node == None:
                deleteLast(first_node)
            elif next_node.front_node == None:
                first_node = deleteFirst(first_node)
            else:
                next_node.front_node.back_node = next_node.back_node
                next_node.back_node.front_node = next_node.front_node
                next_node = None
        else:
            if next_node.back_node == None:
                flag = False
            else:
                next_node = next_node.back_node
    return first_node


def deleteFirst(first_node):
    if first_node.back_node == None:
        first_node = None
    else:
        first_node.back_node.front_node = None
        first_node = first_node.back_node
    return first_node

def deleteLast(first_node):
    flag = True
    check_node = first_node
    while flag:
        if check_node.back_node == None:
            if check_node.front_node == None:
                first_node = None
            else:
                check_node.front_node.back_node = None
                check_node = None
            flag = False
                #first_nodeをNoneにする
        else:
            check_node = check_node.back_node
    return first_node






n = int(input())
first_node = None
for i in range(n):
    tmp = input().split(" ")
    if tmp[0] == "insert":
        first_node = insert(int(tmp[1]),first_node)
    elif tmp[0] == "delete":
        first_node = delete(int(tmp[1]),first_node)
    elif tmp[0] == "deleteFirst":
        first_node = deleteFirst(first_node)
    elif tmp[0] == "deleteLast":
        first_node = deleteLast(first_node)

chk_node = first_node
answer = []
final_flag = True
while final_flag:
    if chk_node.back_node == None:
        final_flag = False
    answer.append(chk_node.value)
    chk_node = chk_node.back_node


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



### 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()