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

typedef struct node {
    int key;
    struct node *prev, *next;
} Node;

Node *nil;

void init(void) {
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

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

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

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

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

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void printList(void) {
    Node *cur = nil->next;
    while (cur != nil) {
        printf("%d", cur->key);
        cur = cur->next;
        if (cur != nil) printf(" ");
    }
    printf("\n");
}

int main(void) {
    int n, i, key;
    scanf("%d", &n);
    char command[13];
    init();

    for (i = 0; i < n; i++) {
        scanf("%s %d", &command, &key);

        if (!strcmp(command, "deleteFirst")) {
            deleteFirst();
        } else if (!strcmp(command, "deleteLast")) {
            deleteLast();
        } else if (command[0] == 'i') {
            insert(key);
        } else {
            deleteKey(key);
        }
    }

    printList();
    return 0;
}
