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

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

Node *nil;

void initialize() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int x){
    Node *i;
    i = (Node *)malloc(sizeof(Node));
    i->key = x;
    
    i->next = nil->next;
    nil->next->prev = i;
    nil->next = i;
    i->prev = nil;
}

void delete_node(int x) {
    Node *now = nil->next;
    while(now != nil) {
        if(now->key == x) {
           now->prev->next = now->next;
           now->next->prev = now->prev;
           free(now);
           break; 
        }
        
        now = now->next;
    }
}
void printList(){
    Node *cur = nil->next;
 
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf ++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
 
    printf("\n");
 
}
 
void delete_last(){
    if(nil->prev == nil) return;
    Node *last = nil->prev;
    nil->prev->prev->next = nil;
    nil->prev = nil->prev->prev;
    free(last);
}

void delete_first() {
    if(nil->next == nil) return;
    Node *first = nil->next;
    nil->next = first->next;
    first->next->prev = nil;
    free(first);
}

int main(void){
    // Your code here!
    int n;
    scanf("%d", &n);
    
    char cmd[20];
    int val;
    initialize();
    for(int i = 0; i < n; i++){
        scanf("%s %d", cmd, &val);
        
        if(strlen(cmd) < 7){
            if(cmd[0] == 'i'){
                insert(val);
            } else {
                delete_node(val);
            }
        } else {
            if(cmd[6] == 'F'){
               delete_first(); 
            } else {
               delete_last();    
            }
        }
    }
    printList();
}

