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

typedef struct p{

    int key;

    struct p *prev, *next;

}node;

void delete(int);
void deletefirst(void);
void deletelast(void);
void insert(int);

node *nil;

int main(){

    int i, n, key;

    char s[20];

    nil=(node *)malloc(sizeof(node));
    nil->next=nil;
    nil->prev=nil;

    scanf("%d", &n);

    for(i=0;i<n;i++){

        scanf("%*c%s", s);

        if(s[0]=='i'){
            
            scanf("%d", &key);
            
            insert(key);

        }

        else if(s[6]=='F') deletefirst();

        else if(s[6]=='L') deletelast();

        else{
            
            scanf("%d", &key);
            
            delete(key);

        }

    }

    node *t=nil->next;

    while(1){

        if(t==nil) break;

        if(i==0) printf(" ");

        printf("%d", t->key);

        t=t->next;

        i=0;

    } 

    printf("\n");

    free(nil);

    return 0;

}

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;

}

void delete(int key){

    node *t=nil->next;
    
    while(1){

        if(t==nil || t->key==key) break;

        t=t->next;

    }

    if(t==nil) return;

    t->prev->next=t->next;

    t->next->prev=t->prev;

    free(t);

}

void deletefirst(){

    node *t=nil->next;

    if(t==nil) return;

    t->prev->next=t->next;

    t->next->prev=t->prev;

    free(t);

}

void deletelast(){

    node *t=nil->prev;

    if(t==nil) return;

    t->prev->next=t->next;

    t->next->prev=t->prev;

    free(t);

}
