#include <stdio.h>
#include <stdlib.h>


int getNumber()
{
	int input;
	scanf("%d", &input);
	return input;
}

void getString(char* input)
{
	scanf("%s", input);
}

typedef struct LinkElement
{
	int key;
	struct LinkElement* pre;
	struct LinkElement* next;
} LE, *PLE;

void display(PLE head, PLE tail)
{
	PLE p = head->next;
	while (p->next != tail)
	{
		printf("%d ", p->key);
		p = p->next;
	}
	printf("%d\n", p->key);
}

int main(void)
{
	int n;
	PLE head, tail;
	head = (PLE) malloc(sizeof(LE));
	tail = (PLE) malloc(sizeof(LE));
	head->key = 0;
	head->pre = NULL;
	head->next = tail;
	tail->key = 0;
	tail->pre = head;
	tail->next = NULL;
	char command[20];

	n = getNumber();
	int i, x;
	PLE p;
	for (i = 0; i < n; i++)
	{
		getString(command);
		if (command[0] == 'i')
		{
			// insert n;
			x = getNumber();
			p = (PLE) malloc(sizeof(LE));
			p->key = x;
			p->next = head->next;
			p->pre = head;
			p->next->pre = p;
			head->next = p;
		}
		else if(command[6] == 'F')
		{
			p = head->next;
			p->next->pre = p->pre;
			p->pre->next = p->next;
			free(p);
		}
		else if(command[6] == 'L')
		{
			p = tail->pre;
			p->pre->next = p->next;
			p->next->pre = p->pre;
			free(p);
		}
		else
		{
			x = getNumber();
			for (p = head->next; p->key != x && p != tail; p = p->next);
			if (p != tail)
			{
				p->pre->next = p->next;
				p->next->pre = p->pre;
				free(p);
			}
		}
	}

	display(head, tail);

	return 0;
}
