#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strcmp()

#define N_LIST 1000020

typedef struct list_tbl
{
	int key;
	struct list_tbl* prev;
	struct list_tbl* next;
} list_t;

int lineno;
list_t list[N_LIST];
int ix;
list_t* head;
list_t* tail;
list_t* room;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
insert(int key)
{
	list_t* l;

	if (ix >= N_LIST)
	{
		fprintf(stderr, "line %d: List overflow. size%d\n", lineno, N_LIST);
		cleanup(1);
	}

	if (room == 0)
		l = &list[ix++];
	else
	{
		l = room;
		room = l->next;
	}

	l->key = key;
	l->next = head;
	list_t* next = head;
	head = l;

	if (next == NULL)
	{
		l->prev = tail;
		tail = l;
	}
	else
	{
		l->prev = next->prev;
		next->prev = l;
	}
}

void
delete(int key)
{
	list_t* next;
	list_t** pnext;
	list_t* l;

	pnext = &head;
	for (l = head; l != NULL && l->key != key; l = l->next)
		pnext = &l->next;

	if (l == NULL)
		return;

	next = l->next;
	*pnext = next;

	if (next == NULL)
		tail = l->prev;
	else
		next->prev = l->prev;

	l->next = room;
	room = l;
}

void
delete_first()
{
	list_t* t = head;
	head = head->next;
	if (head == NULL)
		tail = NULL;
	else
		head->prev = NULL;

	t->next = room;
	room = t;
}

void
delete_last()
{
	list_t* t = tail;
	tail = tail->prev;
	if (tail == NULL)
		head = NULL;
	else
		tail->next = NULL;

	t->next = room;
	room = t;
}

int
main(int argc, char** argv)
{
	char command[15];
	int x = 0;
	int n = 0;
	list_t* l;
	int i;

	head = NULL;
	tail = NULL;
	room = NULL;
	ix = 0;

	scanf("%d", &n);
	lineno = 0;
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s", command);
		if (strcmp(command, "insert") == 0)
		{
			scanf("%d", &x);
			insert(x);
		}
		else if (strcmp(command, "delete") == 0)
		{
			scanf("%d", &x);
			delete(x);
		}
		else if (strcmp(command, "deleteFirst") == 0)
			delete_first();

		else if (strcmp(command, "deleteLast") == 0)
			delete_last();
	}

	const char* sep = "";
	for (l = head; l != NULL; l = l->next)
	{
		printf("%s%d", sep, l->key);
		sep = " ";
	}

	printf("\n");
	return 0;
}