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


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

typedef struct Node_tag Node;


void init_sentinel(Node *sentinel){
    sentinel->prev = sentinel;
    sentinel->next = sentinel;
}

void print_list(Node *sentinel){
    Node* cur;
    int cnt = 0;
    cur = sentinel->next;
    while(cur != sentinel){
        if(cnt > 0){
            putchar(' ');
        }
        cnt++;
        printf("%d", cur->key);
        cur = cur->next;
    }
    putchar('\n');
}

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

void delete_node(Node *sentinel, Node *x){
    if(x == sentinel){
        return;
    }
    (x->prev)->next = x->next;
    (x->next)->prev = x->prev;
    free(x);
}

Node* search_by_key(Node *sentinel, int key){
    Node *cur;
    cur = sentinel->next;
    while (cur != sentinel){
        if(cur->key == key){
            break;
        }
        cur = cur->next;
    }
    return cur;
}

void delete_by_key(Node *sentinel, int key){
    delete_node(sentinel, search_by_key(sentinel, key));
}

int main(void){
    int n, i;
    int key;
    char com[20];
    Node *sentinel = (Node *)malloc(sizeof(Node));

    init_sentinel(sentinel);

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s %d", com, &key);
        if(com[0] == 'i'){ // command is insert x
            insert(sentinel, key);
        }
        else if(com[0] == 'd'){
            if(strlen(com) > 6 && com[6] == 'F'){ // if command is 'deleteFirst'
                delete_node(sentinel, sentinel->next);
            }
            else if(strlen(com) > 6 && com[6] == 'L'){ // if command is 'deleteLast'
                delete_node(sentinel, sentinel->prev);
            }
            else{ // command is delete x
                delete_by_key(sentinel, key);
            }
        }
    }

    print_list(sentinel);

    return 0;
}

