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

#define N_LIST 1001000

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

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

void
insert(int key)
{
	list[ix].key = key;
	list[ix].prev = tail;
	int prev = tail;
	tail = ix;

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

	ix++;
}

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;

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

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

void
delete_first()
{
	tail = list[tail].prev;
	list[tail].next = -1;
}

void
delete_last()
{
	head = list[head].next;
	list[head].prev = -1;
}

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

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

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		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 = tail; l != -1; l = list[l].prev)
	{
		printf("%s%d", sep, list[l].key);
		sep = " ";
	}

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