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

typedef struct{
    int x;
    int prev;   //先頭要素なら-1
    int next;   //末尾要素なら-1
}element;
typedef struct{
    element *e;
    int head,tail;
    int count;
}list;

void insert(list *l){
    int i;
    
    int x;
    scanf("%d\n",&x);
    
    if(l->count==0){
        l->e=(element*)malloc(sizeof(element));
        l->e[0].x=x;
        l->e[0].prev=-1;
        l->e[0].next=-1;
        l->count++;
        l->head=0;
        l->tail=0;
    }else{
        i=l->count;
        l->e=(element*)realloc(l->e,sizeof(element)*(i+1));
        l->e[i].x=x;
        l->e[i].prev=-1;
        l->e[i].next=l->head;
        l->e[l->head].prev=i;
        l->count++;
        l->head=i;
    }
}
void del(list *l){
    int i;
    
    int x;
    scanf("%d\n",&x);
    
    i=l->head;
    while(l->e[i].x!=x){
        i=l->e[i].next;
        if(i==-1)return;
    }
    
    int prev,next;
    prev=l->e[i].prev;
    next=l->e[i].next;
    if(prev!=-1)l->e[prev].next=next;
    else l->head=next;
    if(next!=-1)l->e[next].prev=prev;
    else l->tail=prev;

    l->e[i].x=-1;
    
}
void delFirst(list *l){
    int head=l->head;
    int next=l->e[head].next;
    
    l->e[head].x=-1;
    if(next!=-1)l->e[next].prev=-1;
    else l->tail=-1;
    l->head=next;
}
void delLast(list *l){
    int tail=l->tail;
    int prev=l->e[tail].prev;
    
    l->e[tail].x=-1;
    if(prev!=-1)l->e[prev].next=-1;
    else l->head=-1;
    l->tail=prev;
}
int main(void){
    int i;
    
    int n;
    scanf("%d",&n);
    
    list l;
    l.head=-1;
    l.tail=-1;
    l.count=0;
    
    char command[12];
    for(i=0;i<n;i++){
        scanf(" \n%s",command);
        if(strcmp(command,"insert")==0){
            insert(&l);
        }else if(strcmp(command,"delete")==0){
            del(&l);
        }else if(strcmp(command,"deleteFirst")==0){
            delFirst(&l);
        }else if(strcmp(command,"deleteLast")==0){
            delLast(&l);
        }
    }
    
    i=l.head;
    printf("%d",l.e[i].x);
    i=l.e[i].next;
    while(i!=-1){
        printf(" %d",l.e[i].x);
        i=l.e[i].next;
    }
    printf("\n");
    
}

