#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Node {
    int key;
    struct Node *prev, *next;
};

struct Node *nil;

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

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

//删除第1个含有键值x的结点并返回
int deleteNode(int x) {
    struct Node *s = nil;  //从头节点开始搜索
    while (s->next->key != x && s->next != nil) {
        s = s->next;
    }
    if (s->next == nil) {
        return -1;
    }
    struct Node *tmp = s->next;
    int v = tmp->key;
    s->next = tmp->next;
    tmp->next->prev = s;
    free(tmp);
    return v;
}

//删除链表的表头结点
int deleteFirst() {
    struct Node *tmp = nil->next;
    int v = tmp->key;
    nil->next = tmp->next;
    tmp->next->prev = nil;
    free(tmp);
    return v;
} 

//删除俩表表尾结点
int deleteLast() {
    struct Node *tmp = nil->prev;
    int v = tmp->key;
    nil->prev = tmp->prev;
    tmp->prev->next = nil;
    free(tmp);
    return v;
}

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

int main() {
    init();
    int n, key = 0;
    char com[15];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", com);
        //insert x || delete x
        if (strlen(com) == 6) {
            scanf("%d", &key);
            if (com[0] == 'i') {
                insertNode(key);
            }
            else if(com[0] == 'd') {
                deleteNode(key);
            }
            else {
                printf("unknown command");
            }
        }
        //deleteFirst || deleteLast
        else if (strlen(com) > 6) {
            if (com[6] == 'F') {
                deleteFirst();
            }
            else if (com[6] == 'L') {
                deleteLast();
            }
            else {
                printf("unknown command");
            }
        }
        else {
            printf("unknown command");
        }
    }
    showList();
    return 0;
}
