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

typedef struct _data
{
	int val;
	struct _data *prev;
	struct _data *next;
} data;


data *head, *tail;

void insert(int x)
{
	data *p = (data*)malloc(sizeof(data));
	p->val = x;
	p->prev = NULL;
	p->next = head;
	if (head == NULL) tail = p;
	else head->prev = p;
	head = p;
}

void deleteFirst()
{
	data *p;

	if (head == NULL) return;
	p = head;
	head = head->next;
	free(p);
	if (head == NULL) tail = NULL;
	else head->prev = NULL;
	return;
}

void deleteLast()
{
	data *p;
	if (tail == NULL) return;
	p = tail;
	tail = tail->prev;
	free(p);
	if (tail == NULL) head = NULL;
	else tail->next = NULL;
	return;
}

void delete(int x)
{
	data *p;
	p = head;
	while (p != NULL && p->val != x) p = p->next;

	if (p == NULL) return;
	if (p == head) deleteFirst();
	else if (p == tail) deleteLast();
	else
	{
		p->prev->next = p->next;
		p->next->prev = p->prev;
		free(p);
	}
	return;
}

void terminate()
{
	data *p;
	while ((p = head) != NULL)
	{
		head = head->next;
		free(p);
	}
	tail = NULL;
}

void dump()
{
	data *p = head;
	while (p != NULL)
	{
		printf("%d", p->val);
		if (p->next != NULL) printf(" ");
		p = p->next;
	}
	printf("\n");
}

int main()
{
	int i, n, x;
	char cmd[12];

	head = tail = NULL;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%11s", cmd);
		if (!strcmp(cmd, "insert"))
		{
			scanf("%d", &x);
			insert(x);
		}
		else if (!strcmp(cmd, "delete"))
		{
			scanf("%d", &x);
			delete(x);
		}
		else if (!strcmp(cmd, "deleteFirst")) deleteFirst();
		else if (!strcmp(cmd, "deleteLast"))  deleteLast();
	}

	dump();
	terminate();

	return 0;
}