#include <stdio.h>
#include <stdlib.h>
struct node_t {
	int key;
	struct node_t *next;
	struct node_t *prev;
};
typedef struct node_t Node;
static Node g_first, g_last;

void insert(int key) {
	Node *p;

	p = malloc(sizeof(Node));
	p->key = key;
	p->next = g_first.next;
	p->prev = &g_first;
	g_first.next->prev = p;
	g_first.next = p;
}

void delete_first(void) {
	Node *p;

	p = g_first.next;
	if (p != &g_last) {
		g_first.next = p->next;
		p->next->prev = &g_first;
		free(p);
	}
}

void delete_last(void) {
	Node *p;

	p = g_last.prev;
	if (p != &g_first) {
		g_last.prev = p->prev;
		p->prev->next = &g_last;
		free(p);
	}
}

void delete_key(int key) {
	Node *p;

	for (p = g_first.next; p != &g_last; p = p->next) {
		if (p->key == key) {
			p->prev->next = p->next;
			p->next->prev = p->prev;
			free(p);
			break;
		}
	}
}

void print_node(void) {
	Node *p;
	const char *fmt = "%d";

	for (p = g_first.next; p->key >= 0; p = p->next) {
		printf(fmt, p->key);
		fmt = " %d";
	}
	putchar('\n');
}

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

	g_first.next = &g_last;
	g_last.prev = &g_first;
	g_first.key = g_last.key = -1;
	scanf("%d ", &n);
	while (n--) {
		scanf("%s%d", in, &key);
		if (in[0] == 'i') {
			insert(key);
		} else {
			if (in[6] == '\0') {
				delete_key(key);
			} else if (in[6] == 'F') {
				delete_first();
			} else {
				delete_last();
			}
		}
	}
	print_node();
	return 0;
}