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

void init();
void insert(int);
int delete(int);
void deleteLast();
void deleteFirst();

typedef struct Node {
    int key;
    struct Node *next;
    struct Node *pre;
} Node;

Node *head;

int main() {
    int n;
    int size = 0;
    char command[15];
    int key;
    int i;

    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s", command);

        if (command[0] == 'i') {
            scanf("%d", &key);
            insert(key);
            size++;
        } else if (command[0] == 'd') {
            if(strlen(command) <= 6) {
                scanf("%d", &key);
                size -= delete(key);
            } else if (command[6] == 'F') {
                deleteFirst();
                size--;
            } else if (command[6] == 'L') {
                deleteLast();
                size--;
            }
        }
    }

    Node *node = head->next;
    while (1) {
        printf("%d", node->key);
        node = node->next;

        if (node == head) {
            printf("\n");
            break;
        } else {
            printf(" ");
        }
    }

    return 0;
}

void init() {
    head = (Node *)malloc(sizeof(Node));
    head->next = head;
    head->pre = head;
}

void insert(int key) {
    Node *node = (Node *)malloc(sizeof(Node));
    node->key = key;
    node->next = head->next;
    head->next->pre = node;
    head->next = node;
    node->pre = head;
}

int delete(int key) {
    Node *node = head->next;
    while (node != head && node->key != key) {
        node = node->next;
    }

    if (node == head) {
      return 0;
    }

    node->pre->next = node->next;
    node->next->pre = node->pre;
    free(node);
    return 1;
}

void deleteFirst() {
    Node *node = head->next;
    head->next = head->next->next;
    head->next->pre = head;
    free(node);
}

void deleteLast() {
    Node *node = head->pre;
    head->pre = head->pre->pre;
    head->pre->next = head;
    free(node);
}

