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

typedef struct list_
{
    int data;
    struct list_ *prev;
    struct list_ *next;
} list;

    //リスト先頭挿入
void insert(list *left)
{
	list *n = malloc(sizeof(list));
    scanf("%d",&n->data);
    list *right = left->next;
    left->next = n;
    right->prev = n;
    n->prev = left;
    n->next = right;
}

    //data==キー　削除
void delete(list *head,list *tail)
{
    int d;
    scanf("%d",&d);
    for(list *i = head->next;i != tail;i=i->next)
    {
        if(i->data == d){
            list *left = i->prev;
            list *right = i->next;
            left->next = right;
            right->prev = left;
            free(i);
            break;
        }
    }
}

    //リスト先頭削除
void deleteFirst(list *head)
{
    list *delfir = head->next;
    list *chn = delfir->next;
    chn->prev = head;
    head->next = chn;
    free(delfir);
}

    //リスト末尾削除
void deleteLast(list *tail)
{
    list *dellas = tail->prev;
    list *chn = dellas->prev;
    chn->next = tail;
    tail->prev = chn;
    free(dellas);
}

int main()
{
    int m;
    scanf("%d",&m);
    char order[50];
    list head;
    list tail;
    head.next = &tail;
    tail.prev = &head;
    for(int i=0;i<m;i++)
    {
        scanf("%s",order);
        if(!(strcmp(order,"insert")))  insert(&head);
        else if(!(strcmp(order,"delete")))  delete(&head,&tail);
        else if(!(strcmp(order,"deleteFirst")))  deleteFirst(&head);
        else if(!(strcmp(order,"deleteLast")))  deleteLast(&tail);
    }
    int flg = 0;
    for(list *i = head.next;i != &tail;i=i->next)
    {
        if(i != head.next)   printf(" %d",i->data);
        else printf("%d",i->data);
    }
    printf("\n");
}
