### BUGGY CODE ###

# これもdeque使わないと時間切れになるのか？
from sys import stdin


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


class DoublyLinkedList():
    def __init__(self):
        head = Node()
        head.next = head
        head.prev = head
        self.size = 0
        self.head = head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node
        #self.size += 1

    def delete(self, x):
        node = self.head.next
        while node is not self.head:
            if node.key == x:
                node.prev.next = node.next
                node.next.prev = node.prev
        #        self.size -= 1
                break
            node = node.next

    def deleteFirst(self):
        self.head.next.next.prev = self.head
        self.head.next = self.head.next.next
        #self.size -= 1

    def deleteLast(self):
        self.head.prev.prev.next = self.head
        self.head.prev = self.head.prev.prev
        #self.size -= 1

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(str(node.key))
            node = node.next
        return " ".join(keys)


L = DoublyLinkedList()
n = int(input())
for i in range(n):
    command = stdin.readline().strip().split()
    if command[0] == "insert":
        L.insert(int(command[1]))
    elif command[0] == "delete":
        L.delete(int(command[1]))
    elif command[0] == "deleteFirst":
        L.deleteFirst()
    else:
        L.deleteLast()

print(L.getKeys())



### FIXED CODE ###

import sys


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


class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        if node is self.head:
            return None
        self._delete(node)

    def _delete(self, node):
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys)


L = DoublyLinkedList()
n = int(input())
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass
print(L.getKeys())