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

struct node *nil;

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

struct node *listSearch(int keys)
{
    node *cur=nil->next;
    while(cur!=nil && cur->key!=keys)
        cur=cur->next;

    return cur;
}

void insert(int keys)
{
    node *x=(struct node *)malloc(sizeof(struct node));
    x->key=keys;
    //insert
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}

void Delete(struct node *t)
{
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

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

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

void printList()
{
    node *cur=nil->next;
    while(cur->next != nil)
    {
        printf("%d ", cur->key);
        cur=cur->next;
    }
    printf("%d\n", cur->key);
}
int main()
{
    int n, x,i;
    char comm[12];

    scanf("%d", &n);

    init();

    for(i=0; i<n; i++)
    {
        scanf("%s", comm);
        if(comm[0]=='i')
        {
            scanf("%d", &x);
            insert(x);
        }
        if(comm[0]=='d')
        {
            if(comm[6]=='F') deleteFirst();
            else if(comm[6]=='L') deleteLast();
            else
            {
                scanf("%d", &x);
                Delete(listSearch(x));
            }
        }
    }


    printList();

    return 0;
}