#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
双方向リスト
*/

struct node {
    struct node* next;
    struct node* prev;
    int val;
};
typedef struct node node_t;

node_t* make_new_node(int val) {
    node_t* p = (node_t*)calloc(sizeof(node_t), 1);
    p->val = val;
    p->next = p;
    p->prev = p;
    return p;
}
// 前に挿入
void insert_prev(node_t* cur, node_t* p) {
    cur->prev->next = p;
    p->next = cur;
    p->prev = cur->prev;
    cur->prev = p;
}
// 後に挿入
void insert_next(node_t* cur, node_t* p) {
    p->next = cur->next;
    cur->next->prev = p;
    cur->next = p;
    p->prev = cur;
}
// 削除
void delete_this(node_t* cur) {
    node_t* tmp = cur->next;
    cur->prev->next = tmp;
    cur->next->prev = cur->prev;
}

typedef struct {
    node_t* head;
} list_t;

list_t* make_new_list() {
    list_t* list = (list_t*)calloc(sizeof(list_t), 1);
    node_t* head = make_new_node(0);
    list->head = head;
    return list;
}

void print_list(list_t* list) {
    char sep[2] = {};
    node_t* n = list->head->next;
    while (n != list->head) {
        printf("%s%d", sep, n->val);
        sep[0] = ' ';
        n = n->next;
    }
    putchar('\n');
}

void insert(list_t* list, int val) {
    node_t* n = make_new_node(val);
    insert_next(list->head, n);
}
void deleteFirst(list_t* list) {
    node_t* n = list->head->next;
    if (n == list->head) {
        return;
    }
    delete_this(list->head->next);
}
void deleteLast(list_t* list) {
    node_t* n = list->head->prev;
    if (n == list->head) {
        return;
    }
    delete_this(list->head->prev);
}
void delete (list_t* list, int val) {
    node_t* n = list->head->next;
    if (n == list->head) {
        return;
    }
    while (n != list->head) {
        if (n->val == val) {
            delete_this(n);
            break;
        }
        n = n->next;
    }
}

int main(int argc, char const* argv[]) {
    int n;
    char buf[1024];
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d", &n);
    list_t* list = make_new_list();

    char cmd[32];
    int op;
    for (int i = 0; i < n; i++) {
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%s %d", cmd, &op);
        if (!strcmp("insert", cmd)) {
            insert(list, op);
        } else if (!strcmp("delete", cmd)) {
            delete (list, op);
        } else if (!strcmp("deleteFirst", cmd)) {
            deleteFirst(list);
        } else if (!strcmp("deleteLast", cmd)) {
            deleteLast(list);
        }
    }
    print_list(list);
}

