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

struct node{
    int key;
    struct node *prev;
    struct node *next;
};
typedef struct node node_t;

node_t *head, *tail;

int getint(char str[], int c);
void insert(int x);
void delete(int x);
void deleteFirst();
void deleteLast();

int main( void ){
    int n,i,d;
    head = malloc(sizeof(node_t));
    head->key = -1; head->next = NULL; head->prev = NULL;
    tail = head;
    char com[40], num[20];

    fgets(num,20,stdin);
    n = atoi(num);

    for(i = 0; i < n; i++){
        fgets(com, 40, stdin);
        if(strncmp(com,"deleteFirst",11) == 0){
            deleteFirst();
        }
        else if(strncmp(com,"deleteLast",10) == 0){
            deleteLast();
        }
        else if(strncmp(com,"insert",6) == 0){
            d = getint(com, 6);    //文字を数字として取得
            insert(d);
        }
        else if(strncmp(com,"delete",6) == 0){
            d = getint(com, 6);
            delete(d);
        }
    }
    node_t *p;
    p = malloc(sizeof(node_t));
    for(p = head; p != tail; p = p->next){
        printf("%d", p->key);
        if(p != tail->prev){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

int getint(char str[], int c){    //cは文字部分の長さ
    int count = 0, x = 0;
    int i, a = 0;
    for(i = c + 1; str[i] != '\n'; i++){    // 012345_6_789...
        count++;
    }
    for(i = c + count; i >= c + 1; i--){
        a++;
        x += (str[i] - '0') * pow(10, a - 1);
    }
    return x;
}

void insert(int x){
    node_t *p;
    p = malloc(sizeof(node_t));
    p->key = x;
    p->next = head;
    p->prev = NULL;
    p->next->prev = p;
    head = p;
}

void delete(int x){
    node_t *p;
    p = malloc(sizeof(node_t));
    for(p = head; p != tail; p = p->next){
        if(p->key == x){
            if(p == head){
                deleteFirst();
            }
            else if(p == tail){
                deleteLast();
            }
            else{
                p->prev->next = p->next;
                p->next->prev = p->prev;
            }
            break;
        }
    }
}

void deleteFirst(){
    head = head->next;
    free(head->prev);
    head->prev = NULL;
}

void deleteLast(){
    tail = tail->prev;
    free(tail->next);
    tail->next = NULL;
}

