#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
    NodePointer n;
    for(n = nil->next; n != nil && n->key != key; n = n->next);
    return n;
}

void init(){
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    NodePointer cur;
    int isf = 1;
    for(cur = nil->next;cur != nil; cur = cur->next){
        if(isf == 0) printf(" ");
        printf("%d", cur->key);
        isf = 0;
    }
    printf("\n");
}

void deleteNode(NodePointer t){
    NodePointer delnode;
    delnode = t;
    delnode->prev->next = delnode->next;
    delnode->next->prev = delnode->prev;
    free(delnode);
}

void deleteFirst(){
    NodePointer t = nil->next;
    if(t == nil) return;
    deleteNode(t);
}

void deleteLast(){
    NodePointer t = nil->prev;
    if(t == nil) return;
    deleteNode(t);
}

void delete(int key){
    NodePointer t;
    t = listSearch(key);
    if(t == nil) return;
    deleteNode(t);
}

void insert(int key){
    NodePointer newnode;
    newnode = malloc(sizeof(struct node));
    newnode->key = key;
    newnode->next = nil->next;
    nil->next->prev = newnode;
    nil->next = newnode;
    newnode->prev = nil;
}

int main(){
    int key,n,i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d",&n);
    init();
    for(i = 0; i < n; i++){
        scanf("%s%d",com,&key);
        if(com[0] == 'i'){
            insert(key);
            np++;
            size++;
        }
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }
            else{
                delete(key);
                nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}


