#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct Node{
    int key;
    struct Node *prev;
    struct Node *next;
};
typedef struct Node Node;
Node *nil;
void init(void){
    nil = (Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
Node* listSearch(int key){
    Node *cur=nil->next;
    while (cur!=nil&&cur->key!=key) {
        cur = cur->next;
    }
    return cur;
}
void deleteNode(Node *t){
    if (t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
void deleteFirst(void){
    deleteNode(nil->next);
}
void deleteLast(void){
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}
void printList(void){
    Node *cur=nil->next;
    while (cur!=nil) {
        printf("%d",cur->key);
        if (cur->next!=nil) {
            printf(" ");
        }
        cur = cur->next;
    }
    printf("\n");
}
int main(){
    int n, i, x;
    char a[20];
    init();
    scanf("%d",&n);
    for (i=0;i<n;i++) {
        scanf("%s",a);
        if (a[0]=='i') {
            scanf("%d",&x);
            insert(x);
        } else if (a[0]=='d') {
            if (strlen(a)>6) {
                if (a[6]=='F') {
                    deleteFirst();
                } else if (a[6]=='L') {
                    deleteLast();
                }
            } else {
                scanf("%d",&x);
                deleteKey(x);
            }
        }
    }
    printList();
    return 0;
}

