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

typedef struct _Node {
    int x;
    struct _Node *prev;
    struct _Node *next;
} Node;

Node *head = NULL, *tail = NULL;

/* Print all elements to stdin */
void dump() {
    int hoge = 0;
    Node *p = head;
    while (p != NULL) {
        if (hoge == 0)  printf("%d",  p->x);
        else            printf(" %d", p->x);
        ++hoge;
        p = p->next;
    }
    printf("\n");
}

void insert(int x) {
    Node *nod = malloc(sizeof(Node));;
    nod->x = x;
    nod->prev = NULL;
    nod->next = NULL;

    if (head == NULL) {
        head = nod;
        tail = nod;
    } else {
        nod->next = head;
        head->prev = nod;
        head = nod;
    }
    //dump();

}

void delete(int x) {
    Node *p = head;
    int flg = 0;
    
    while (flg == 0 && p != NULL) {
        //printf("x = %d\n", p->x);
        if (p->x == x) {
            Node *c = p;
            if (c->prev != NULL) {
                p->prev->next = c->next;
            } else {    /* if delete head */
                head = c->next;
            }
            
            if (c->next != NULL) {
                p->next->prev = c->prev;
            } else {    /* if delete tail */
                tail = c->prev;
            }
            flg = 1;
        } else {
            p = p->next;
        }
    }
}

void deleteFirst() {
    if (head == tail) {
        head = NULL;
        tail = NULL;
    } else if (head != NULL) {
        if (head->next != NULL) head->next->prev = NULL;
        head = head->next;
    }
}

void deleteLast() {
    if (head == tail) {
        head = NULL;
        tail = NULL;
    } else if (tail != NULL) {
        if (tail->prev != NULL) tail->prev->next = NULL;
        tail = tail->prev;
    }
}

int main(int argc, char **argv) {

    int n;
    scanf("%d\n", &n);

    int i;
    int x;
    char buf[256];
    char tmp[256];
    for (i = 0; i < n; ++i) {
        fgets(buf, 256, stdin);
        
        if (buf[0] == 'i' || buf[6] == ' ') {
            /* read x */
            sscanf(buf, "%s %d", tmp, &x);

            if (buf[0] == 'i') insert(x);
            else               delete(x);     
        } else if (buf[6] == 'F') {
            deleteFirst();
        } else if (buf[6] == 'L') {
            deleteLast();
        }
    }

    dump();
    
    return 0;
}