#include <stdio.h>
#include <stdlib.h>
 
typedef struct nodetag {
    unsigned int key;
    struct nodetag *next;
    struct nodetag *prev;
} Node;
 
Node *createNode(int key)
{
    Node *node = malloc(sizeof(Node));
    node->key = key;
    node->next = node->prev = NULL;
 
    return node;
}
 
void insert(Node *node, Node **head, Node **tail)
{
    if(*tail == NULL || *head == NULL) {
        node->next = node->prev = NULL;
        *head = *tail = node;
    } else {
        (*tail)->next = node;
        node->prev = *tail;
        node->next = NULL;
        *tail = node; 
    }
}
 
void delete(int key, Node **head, Node **tail)
{
    Node *node = *tail;
 
    while(node != NULL && node->key != key) {
        node = node->prev;
    }
    if(node == NULL)
        return;
    if(node->prev == NULL) {
        (node->next)->prev = NULL;
        *head = node->next;
    } else if(node->next == NULL) {
        (node->prev)->next = NULL;
        *tail = node->prev;
    } else {
        (node->prev)->next = node->next;
        (node->next)->prev = node->prev;
    }
    free(node);
}
 
void deleteFirst(Node **head, Node **tail)
{
    Node *node = *tail;
 
    if(tail == NULL)
        return;
 
    *tail = (*tail)->prev;
    if(*tail == NULL) {
        *head = NULL;
        free(node);
        return;
    }
    (*tail)->next = NULL;
    free(node);
}
 
void deleteLast(Node **head, Node **tail)
{
    Node *node = *head;
 
    if(node == NULL)
        return;
 
    *head = (*head)->next;
    if(*head == NULL) {
        *tail = NULL;
        free(node);
        return;
    }
    (*head)->prev = NULL;
    free(node);
}
 
int main(void)
{
    int i, n, key;
    char command[11];
    Node *tail = NULL, *head = NULL, *node;
 
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%s", command); 
        if(strcmp(command, "insert") == 0) {
            scanf("%d", &key);
            node = createNode(key);
            insert(node, &head, &tail); 
        } else if(strcmp(command, "delete") == 0) {
            scanf("%d", &key);
            delete(key, &head, &tail);
        } else if(strcmp(command, "deleteFirst") == 0) {
            deleteFirst(&head, &tail);
        } else if(strcmp(command, "deleteLast") == 0){
            deleteLast(&head, &tail);
        } else {
            printf("command not found: %s\n", command);
        }
    }
    printf("%d", tail->key);
    tail = tail->prev;
    while(tail != NULL) {
        printf(" %d", tail->key);
        tail = tail->prev;
    }
    printf("\n");
 
    return 0;
}