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

void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}

// positive only
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}

typedef struct ListKey {
    int num;
} ListKey;
bool listkey__equal(ListKey *a, ListKey *b) {
    return a->num == b->num;
}
typedef struct ListDat {
    ListKey key;
    struct ListDat *prev;
    struct ListDat *next;
} ListDat;
typedef struct List {
    size_t len;
    ListDat *hdr;
} List;
#define list_init(l) ((l) ? ((l)->len = 0, (l)->hdr = NULL) : 0)
#define list_len(l) ((l) ? (l)->len : 0)
#define list_delete_first(l) ((l)->len ? list__delete((l), (l)->hdr->next) : 0)
#define list_delete_last(l) ((l)->len ? list__delete((l), (l)->hdr->prev) : 0)
void list_insert(List *l, ListKey x) {
    ListDat *new_dat = malloc(sizeof(ListDat));
    if(l->len) {
        new_dat->next = l->hdr->next;
        l->hdr->next->prev = new_dat;
        l->hdr->next = new_dat;
    } else {
        l->hdr = malloc(sizeof(ListDat));
        l->hdr->prev = l->hdr->next = new_dat;
        new_dat->next = l->hdr;
    }
    new_dat->key = x;
    new_dat->prev = l->hdr;
    l->len++;
}
void list__delete(List *l, ListDat *a) {
    a->prev->next = a->next;
    a->next->prev = a->prev;
    free(a);
    l->len--;
}
void list_delete(List *l, ListKey x) {
    for(ListDat *it = l->hdr->next; it != l->hdr; it = it->next) {
        if(listkey__equal(&x, &it->key)) {
            list__delete(l, it);
            break;
        }
    }
}
void list_print(List *l) {
    for(ListDat *it = l->hdr->next; it != l->hdr->prev; it = it->next) {
        put_uint(it->key.num);
        putchar_unlocked(' ');
    }
    put_uint(l->hdr->prev->key.num);
    putchar_unlocked('\n');
}
int main(int argc, char **argv) {
    int n = get_uint();
    List l;
    list_init(&l);
    for(int i = 0; i < n; ++i) {
        char str[16];
        get_str(str);
        if(strlen(str) == 6 && strncmp(str, "insert", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_insert(&l, key);
        } else if(strlen(str) == 6 && strncmp(str, "delete", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_delete(&l, key);
        } else if(strlen(str) == 11 && strncmp(str, "deleteFirst", 11) == 0) {
            list_delete_first(&l);
        } else if(strlen(str) == 10 && strncmp(str, "deleteLast", 10) == 0) {
            list_delete_last(&l);
        }
    }
    list_print(&l);
    return 0;
}

