#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#define N_LIST 1000000

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

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

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

void
insert(int key)
{
	int l;

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

		l = ix++;
	}
	else
	{
		l = room;
		room = list[l].next;
	}

	list[l].key = key;
	list[l].next = head;
	int next = head;
	head = l;

	if (next == -1)
	{
		list[l].prev = tail;
		tail = l;
	}
	else
	{
		list[l].prev = list[next].prev;
		list[next].prev = l;
	}
}

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

	pnext = &head;
	for (l = head; l != -1 && list[l].key != key; l = list[l].next)
		pnext = &list[l].next;

	if (l == -1)
		return;

	next = list[l].next;
	*pnext = next;

	if (next == -1)
		tail = list[l].prev;
	else
		list[next].prev = list[l].prev;

	list[l].next = room;
	room = l;
}

void
delete_first()
{
	int t = head;
	head = list[head].next;
	if (head == -1)
		tail = -1;
	else
		list[head].prev = -1;

	list[t].next = room;
	room = t;
}

void
delete_last()
{
	int t = tail;
	tail = list[tail].prev;
	if (tail == -1)
		head = -1;
	else
		list[tail].next = -1;

	list[t].next = room;
	room = t;
}

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

	head = -1;
	tail = -1;
	room = 0;
	ix = 0;

	scanf("%d", &n);
	lineno = 0;
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s", command);
		switch (command[0])
		{
		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'd':
			if (command[6] == 'F')
				delete_first();

			else if (command[6] == 'L')
				delete_last();

			else
			{
				scanf("%d", &x);
				delete(x);
			}

			break;
		}
	}

	const char* sep = "";
	for (l = head; l != -1; l = list[l].next)
	{
		printf("%s%d", sep, list[l].key);
		sep = " ";
	}

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