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

typedef struct Node {
    int value;
    struct Node *prev;
    struct Node *next;
} Node;

Node *sentinel;
int size;

Node* search(int keyValue) {
    Node *target = sentinel->next;

    while (target != sentinel && target->value != keyValue) {
        target = target->next;
    }

    return target;
}

// initialize first Node
void initSentinel() {
    sentinel = (Node *)malloc(sizeof(Node));
    sentinel->next = sentinel;
    sentinel->prev = sentinel;
    size = 1;
}

void insert(int value) {
    Node *node = (Node *)malloc(sizeof(Node));
    node->value = value;

    if (sentinel->next == sentinel) {
        sentinel->prev = node;
        node->next = sentinel;

    } else {
        node->next = sentinel->next;
        sentinel->next->prev = node;
    }

    node->prev = sentinel;
    sentinel->next = node;

    size++;
}

void deleteNode(Node *target) {
    if (target == sentinel) { return; }

    target->prev->next = target->next;
    target->next->prev = target->prev;
    free(target);

    size--;
}

void delete(int keyValue) {
    deleteNode(search(keyValue));
}

void deleteFirst() {
    deleteNode(sentinel->next);
}

void deleteLast() {
    deleteNode(sentinel->prev);
}

void printList() {
    Node *target = sentinel->next;
    while(target != sentinel) {
        if (target->next == sentinel) {
            printf("%d\n", target->value);
        } else {
            printf("%d ", target->value);
        }

        target = target->next;
    }
}

int main() {

    // command count
    int N;
    scanf("%d", &N);

    // initialize
    initSentinel();

    char command[100];
    int value = 0;

    for (int i = 0; i < N; i++) {
        scanf("%s", command);

        if (strlen(command) > 6) {
            if (command[6] == 'F') {
                deleteFirst();

            } else {
                deleteLast();
            }

        } else {
            scanf("%d", &value);
            if (command[0] == 'i') {
                insert(value);

            } else {
                delete(value);
            }
        }
    }

    printList();

    return 0;
}

