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

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

int lineno;
list_t list[N_LIST];
int ix;
int nil;
int room;

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

void
init()
{
	nil = 0;
	list[nil].key = -1;
	list[nil].next = nil;
	list[nil].prev = nil;
	ix = 1;
	room = 0;
}

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 = list[nil].next;
	list[l].prev = nil;
	list[list[nil].next].prev = l;
	list[nil].next = l;
}

void
_delete(int l)
{
	if (l == nil)
		return;

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

void
delete(int key)
{
	int l;

	for (l = list[nil].next; l != nil; l = list[l].next)
	{
		if (list[l].key == key)
		{
			_delete(l);
			return;
		}
	}
}

void
delete_first()
{
	_delete(list[nil].next);
}

void
delete_last()
{
	_delete(list[nil].prev);
}

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

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

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

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

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

			break;
		}
	}

	for (l = list[nil].next; l != nil; l = list[l].next)
		printf("%d%c", list[l].key, list[l].next != nil ? ' ' : '\n');

	return 0;
}