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

typedef struct node_tag
{
    int key;
    struct node_tag *prev, *next;
}node;
    char command_1[] = "insert";
    char command_2[] = "delete";
    char command_3[] = "deleteFirst";
    char command_4[] = "deleteLast";

node *nil;

int decision(char *moji)
{
   if(strcmp(command_4, moji) == 0){
       return 4;
   }else if(strcmp(command_3, moji) == 0){
       return 3;
   }else if(strcmp(command_2, moji) == 0){
       return 2;
   }else{
       return 1;
   }
}

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

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

node* listsearch(int key)
{
    node *cur = nil->next;
    while( cur != nil && cur->key != key ){
        cur = cur->next;
    }
    return cur;
}

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

void deletefirst()
{
    deletenode(nil->next);
}

void deletelast()
{
    deletenode(nil->prev);
}

void deletekey(int key)
{
    deletenode(listsearch(key));
}

int main()
{
    int n, i, key;
    char tmp[15];
    init();

    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%s %d", tmp, &key);
        switch(decision(tmp)){
        case 1:
            insert(key);
            break;
        case 2:
            deletekey(key);
            break;
        case 3:
            deletefirst();
            break;
        case 4:
            deletelast();
            break;
        }
    }
    node *hoge = nil->next;
    i = 0;
    while( hoge != nil ){
        if(i++ > 0) printf(" ");
        printf("%d", hoge->key);
        hoge = hoge->next;
    }
    printf("\n");
    return 0;
}