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

struct node{
    int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * Node;
Node nil;

Node listSerch(int key){
    Node cur = nil -> next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
        return cur;
}
    
void init(){
    nil = malloc(sizeof(struct node));
    nil -> next = nil;
    nil -> prev = nil;
}

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 deleteNode(Node t){
    if ( t == nil ) return;
    Node a = t -> prev, b = t -> next;
    a -> next = t -> next;
    b -> prev = t -> prev;
    free(t);
}

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

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

void deletekey(int key){
    Node t = listSerch(key);
    deleteNode(t);
}

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

int main(){
    int key, n, i;
    char com[10];
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ){
        scanf("%s%d" , com, &key);
        if( com[0] == 'i') {insert(key);}
        else if(com[0] == 'd') {
            if( strlen(com) > 6) {
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L')deleteLast();
            }else {
                deletekey(key);
            }
        }
    }

    printlist();
    return 0;
}
