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

struct Node {
    int key;
    struct Node *next;
    struct Node *prev;
};
typedef struct Node node_t;
node_t *root;

int N;

void insert(int x)
{
    node_t *new = (node_t*)malloc(sizeof(node_t));
    new->key = x;
    new->next = root->next;
    new->prev = root;
    root->next->prev = new;
    root->next = new;
}

void deleteNode(node_t *p)
{
    p->prev->next = p->next;
    p->next->prev = p->prev;
    free(p);
}

void delete(int x)
{
    node_t *p = root->next;
    while (p != NULL) {
        if (p->key == x) {
            deleteNode(p);
            return;
        }
        p = p->next;
    }    
}

void deleteFirst()
{
    deleteNode(root->next);
}

void deleteLast()
{
    deleteNode(root->prev);
}

void printList()
{
    node_t *p = root->next;
    
    while (p != root) {
        printf("%d", p->key);
        p = p->next;
        if (p != root) {
            printf(" ");
        }
    }
    puts("");
}

int main()
{
    root = (node_t*)malloc(sizeof(node_t));
    root->next = root->prev = root;
    
    int i, j;
    char cmd[15];
    int x;
    
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%s", cmd);
        switch (cmd[0]) {
        case 'i':
            scanf("%d", &x);
            insert(x);                
            break;
        case 'd':
            switch (cmd[6]) {
            case 'F':
                deleteFirst();
                break;
            case 'L':
                deleteLast();
                break;
            default:
                scanf("%d", &x);
                delete(x);
                break;
            }
            break;                
        }
    }
    
    printList();
    
    return 0;
}