# Original solution
import sys


class mydeque:
    class cell:
        def __init__(self,x,y = None,z = None):
            self.data = x
            self.next = y
            self.prev = z

    def __init__(self):
        head = mydeque.cell(None)
        head.next = head
        head.prev = head
        self.size = 0
        self.head = head

    def push_front(self,x):
        h = self.head
        q = h.next
        p = mydeque.cell(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def push_back(self,x):
        h = self.head
        p = h.prev
        q = mydeque.cell(x,h,p)
        h.prev = q
        p.next = q
        self.size += 1

    def delete_top(self):
        h = self.head
        top = h.next
        nexttop = top.next
        h.next = nexttop
        nexttop.prev = h
        self.size -= 1

    def delete_last(self):
        h = self.head
        last = h.prev
        prevlast = last.prev
        h.prev = prevlast
        prevlast.next = h
        self.size -= 1

    def delete_find(self,target):
        h = self.head
        now_data = h.next
        while now_data != self.head:
            if now_data.data == target:
                next_now = now_data.next
                prev_now = now_data.prev
                next_now.prev = prev_now
                prev_now.next = next_now
                self.size -= 1
                break
            now_data = now_data.next

    def allprint(self):
        h = self.head.next
        for i in range(self.size):
            if i == self.size - 1:
                print(h.data)
            else:
                print(h.data, end=" ")
                h = h.next

# with open("input.txt","r") as f:
queue = int(input())
length = 0
myd = mydeque()
for q in range(queue):
    command = [n for n in input().strip("\n").split(' ')]
    if command[0] == "insert":
        myd.push_front(command[1])
    elif command[0] == "delete":
        myd.delete_find(command[1])
    elif command[0] == "deleteFirst":
        myd.delete_top()
    else:
        myd.delete_last()
myd.allprint()


# Optimized solution
import sys


class mydeque:
    class cell:
        def __init__(self,x,y = None,z = None):
            self.data = x
            self.next = y
            self.prev = z

    def __init__(self):
        head = mydeque.cell(None)
        head.next = head
        head.prev = head
        self.size = 0
        self.head = head

    def push_front(self,x):
        h = self.head
        q = h.next
        p = mydeque.cell(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def push_back(self,x):
        h = self.head
        p = h.prev
        q = mydeque.cell(x,h,p)
        h.prev = q
        p.next = q
        self.size += 1

    def delete_top(self):
        h = self.head
        top = h.next
        nexttop = top.next
        h.next = nexttop
        nexttop.prev = h
        del top
        self.size -= 1

    def delete_last(self):
        h = self.head
        last = h.prev
        prevlast = last.prev
        h.prev = prevlast
        prevlast.next = h
        del last
        self.size -= 1

    def delete_find(self,target):
        h = self.head
        now_data = h.next
        while now_data != self.head:
            if now_data.data == target:
                next_now = now_data.next
                prev_now = now_data.prev
                next_now.prev = prev_now
                prev_now.next = next_now
                del now_data
                self.size -= 1
                break
            now_data = now_data.next

    def allprint(self):
        h = self.head.next
        for i in range(self.size):
            if i == self.size - 1:
                print(h.data)
            else:
                print(h.data, end=" ")
                h = h.next

# with open("input.txt","r") as f:
queue = int(input())
length = 0
myd = mydeque()
for q in range(queue):
    command = [n for n in input().strip("\n").split(' ')]
    if command[0] == "insert":
        myd.push_front(command[1])
    elif command[0] == "delete":
        myd.delete_find(command[1])
    elif command[0] == "deleteFirst":
        myd.delete_top()
    else:
        myd.delete_last()
myd.allprint()