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

struct Node{
    int key;
    struct Node *next,*prev;
};

typedef struct Node Node;

Node *nil;

Node *listSearch(int);
void init();
void printList();
void deleteNode(Node*);
void deleteFirst();
void deleteLast();
void deleteKey(int);
void insertKey(int);

int main(){
    int key,n,i;
    char command[11];

    scanf("%d",&n);

    init();

    for(i=0;i<n;i++){
        scanf("%s%d",command,&key);

        if(command[0]=='i') insertKey(key);
        else if(command[0]=='d'){
            if(command[6]=='F') deleteFirst();
            else if(command[6]=='L') deleteLast();
            else deleteKey(key);
        }
    }

    printList();

    return 0;
}

Node *listSearch(int key){
    Node *current=nil->next;

    while(current!=nil&&current->key!=key){
        current=current->next;
    }

    return current;
}

void init(){
    nil=(Node*)malloc(sizeof(Node));

    nil->next=nil;
    nil->prev=nil;
}

void printList(){
    int i;
    Node *current=nil->next;

    for(i=0;;i++){
        if(current==nil) break;
        if(i==0) printf("%d",current->key);
        else printf(" %d",current->key);
     
        current=current->next;
    }
    printf("\n");

}

void deleteNode(Node *x){
    if(x==nil) return;

    x->prev->next=x->next;
    x->next->prev=x->prev;

    free(x);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insertKey(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;
}
