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

typedef struct Node_ Node;

struct Node_ {
    int key;
    Node* prev;
    Node* next;
};

Node* nil;

static bool isEmpty()
{
    return (nil->next == nil);
}


static void insert(int key)
{
    Node* x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->prev = nil;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
}

static Node* search(int key)
{
    Node* cur = nil->next;
    while (cur != NULL && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

static void deleteNode(Node* node)
{
    if (node == NULL)
        return;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    free(node);
}

static void deleteFirst()
{
    deleteNode(nil->next);
}

static void deleteLast()
{
    deleteNode(nil->prev);
}

static void deleteKey(int key)
{
    deleteNode(search(key));
}

static void printList()
{
    Node* cur = nil->next;
    int i = 0;

    while (cur != nil) {
        if (i++ > 0) {
            printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

static void initialize()
{
    nil = (Node*)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

static void finalize()
{
    while (!isEmpty()) {
        deleteFirst();
    }
    free(nil);
}

int main()
{
    int n, key;
    char command[20];

    initialize();
    scanf("%d", &n);

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

        if (command[0] == 'i') {
            insert(key);
        } else if (command[0] == 'd') {
            if (strlen(command) > 6) {
                if (command[6] == 'F') {
                    deleteFirst();
                } else if (command[6] == 'L') {
                    deleteLast();
                }
            } else {
                deleteKey(key);
            }
        }
    }

    printList();
    finalize();
    return 0;
}
