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

struct Node {
    int key;
    struct Node *next;
    struct Node *prev;
};
typedef struct Node t_Node;
t_Node *list;

int N;

void insert(int x)
{
    t_Node *new = (t_Node*)malloc(sizeof(t_Node));
    new->key = x;
    new->prev = NULL;
    new->next = NULL;
    
    if (list->key == -1) {
        list = new;
    }
    else {
        list->prev = new;
        new->next = list;
        list = new;
    }
}

void delete(int x)
{
    t_Node *node = list;
    while (node != NULL) {
        if (node->key == x) {
            t_Node *prev = node->prev;
            t_Node *next = node->next;
            // ???????????????
            if (prev == NULL) {
                next->prev = NULL;
                list = next;
            }
            // ????°??????????
            else if (next == NULL) {
                prev->next = NULL;
            }
            // ???????????????
            else {
                prev->next = next;
                next->prev = prev;
            }
            free(node);
            return;
        }
        node = node->next;
    }
}

void deleteFirst()
{
    // ???????????°1???????????????
    if (list->next == NULL) {
        list->key = -1;
        return;
    }
    
    list = list->next;
    free(list->prev);
    list->prev = NULL;
}

void deleteLast()
{
    t_Node *node = list;
    while (node != NULL) {
        if (node->next == NULL) {
            break;
        }
        node = node->next;
    }
    // ???????????° 2??\???
    if (node->prev != NULL) {
        node->prev->next = NULL;
        free(node);
    }
    else {
        node->key = -1;
    }
}

void printList()
{
    t_Node *node = list;
    if (node->key == -1) {
        return;
    }
    while (node != NULL) {
        printf("%d", node->key);
        if (node->next != NULL) {
            printf(" ");
        }
        node = node->next;
    }
    puts("");
}

int main()
{
    list = (t_Node*)malloc(sizeof(t_Node));
    list->next = list->prev = NULL;
    list->key = -1;
    
    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;
}