//============================================================================
// Doubly Linked List
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
struct List{
    struct List *prev;
    struct List *next;
    
    long   key;
};
typedef struct List TList;
//============================================================================
#define MAXCMD 4
const char Command[MAXCMD][20]={
    "insert",
    "delete",
    "deleteFirst",
    "deleteLast"
};
TList *top,*btm;

//============================================================================
void dump(int *A, int N)
{
    int i;

    for (i=0; i<N; i++){
        if (i)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}
//============================================================================
void cdump(char *str)
{
    int i;

    printf("%d:", strlen(str));;
    for (i=0; i<strlen(str); i++){
        if (i)
            printf(" ");
        printf("%02X", (unsigned char)str[i]);
    }
    printf("\n");
}
//============================================================================
TList *searchlist(TList *lst, long key)
{
    while(lst!=NULL){
        if (lst->key==key)
            return lst;
        lst=lst->next;
    }
    return NULL;
}
//============================================================================
void insertlist(long key)
{
    TList *lst;

    lst=malloc(sizeof(TList));
    if (top==NULL){
        top=lst;
        btm=lst;
        top->prev=NULL;
        top->next=NULL;
    }else{
       lst->next=top;
       lst->prev=top->prev;
       top->prev=lst;
       top=lst;
    }
    lst->key=key;
}
//============================================================================
void deletelist(TList *lst)
{
    if (lst==NULL)
        return;
    if (lst==top)
        top=top->next;
    if (lst==btm)
        btm=btm->prev;
    if (lst->prev!=NULL)
        lst->prev->next=lst->next;
    if (lst->next!=NULL)
        lst->next->prev=lst->prev;
    free(lst);
}
//============================================================================
void cleanlist(void)
{
    while (top->next!=NULL)
        deletelist(top->next);
    deletelist(top);
}
//============================================================================
void process(char *cmd, long key)
{
    TList *lst;

    if (*cmd=='i')
        insertlist(key);
    else
    if (strlen(cmd)==6){
        lst=searchlist(top, key);
        deletelist(lst);
    }else
    if (cmd[6]=='F')
        deletelist(top);
    if (cmd[6]=='L')
        deletelist(btm);
}
//============================================================================
void input(void)
{
    long i,n,key; TList *lst; char cmd[20];

    scanf("%ld", &n);
    top=btm=NULL;
    for (i=0; i<n; i++){
        scanf("%s %ld%", cmd, &key);
        //printf("%ld entered %s %ld\n", i, cmd, key);
        process(cmd, key);
    }
    for (n=0,lst=top; lst!=NULL; lst=lst->next,n++){
        if (n) printf(" ");
        printf("%d", lst->key);
    }
    printf("\n");
    cleanlist();
}
//============================================================================
int main(void)
{
    input();
    return 0;
}
//============================================================================