#include <stdio.h>
#include <stdlib.h>
#include <string.h>
   
struct node{
    int key;
    struct node *next;
    struct node *prev;
};
   
typedef struct node * NodePointer;
NodePointer nil;
 
void insert(int keydata){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = keydata;
    x->next = nil->next;
    x->prev = nil;
    nil->next = x;
    x->next->prev = x;
}
 
int delete(int keydata){
    NodePointer p;
    p = nil->next;

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

    if(p == nil){
        return 0;
    }
    
    else{
        p->prev->next = p->next;
        p->next->prev = p->prev;
        free(p);

        return 0;
    }
}
 
int deleteFirst(){
    NodePointer p;
    p = nil->next;
    nil->next = p->next;
    p->next->prev = nil;
    free(p);

    return 0;
}

int deleteLast(){
    NodePointer p;
    p = nil->prev;
    p->prev->next = nil;
    nil->prev = p->prev;
    free(p);

    return 0;
}
 
void init(){
    nil->next = nil;
    nil->prev = nil;
}
 
int main(){
    int n, i, keydata;
    char com[12];

    NodePointer p;

    scanf("%d",&n);
    nil=malloc(sizeof(struct node));
    init();
    
    for(i=0;i<n;i++){
        scanf("%s",com);

        if(strlen(com)>6){
            if(com[6]=='F') {
                deleteFirst();
            }
            else{
                deleteLast();
            }
        }
        else{
            scanf("%d",&keydata);
            if(com[0]=='i'){
                insert(keydata);
            }
            else{
                delete(keydata);
            }
        }
    }
  
    for(p = nil->next; p != nil->prev; p = p->next){
        printf("%d ",p->key);
    }
    
    printf("%d\n",p->key);
    free(nil);
    
    return 0;
}