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

struct ListNode
{
	int value;
	struct ListNode *prev;
	struct ListNode *next;
};

struct ListNode *nil;

void init()
{
	nil = (struct ListNode *)malloc(sizeof(struct ListNode));
	if (NULL == nil)
		return ;
	nil->prev = nil;
	nil->next = nil;

	return ;
}

void insert(int value)
{
	struct ListNode *cur;

	cur = (struct ListNode *)malloc(sizeof(struct ListNode));
	if (NULL == cur)
		return ;
	cur->value = value;
	cur->next = nil->next;
	nil->next->prev = cur;
	nil->next = cur;
	cur->prev = nil;

	return ;
}

struct ListNode * search(int value)
{
	struct ListNode *cur = nil->next;

	while ((cur != nil) && (cur->value != value))
	{
		cur = cur->next;
	}

	return cur;
}

void delete(struct ListNode *cur)
{
	if (cur == nil)
		return;
	cur->next->prev = cur->prev;
	cur->prev->next = cur->next;
	free(cur);

	return ;
}

void deleteFirst()
{
	delete(nil->next);
	return ;
}

void deleteLast()
{
	delete(nil->prev);
	return ;
}

void deleteKey(int key)
{
	delete(search(key));
	return ;
}

void printList()
{
	struct ListNode *cur = nil->next;
	int isf = 0;
	while (1)
	{
		if (cur == nil)
			break;
		if (isf++ > 0)
			printf(" ");
		printf("%d", cur->value);
		cur = cur->next;
	}

	printf("\n");

	return ;
}

int main()
{
	int num;
	int i;
	int value;
	char cmd[20];

	init();
	scanf("%d", &num);
	for (i = 0; i < num; i++)
	{
		scanf("%s", cmd);
		if (cmd[0] == 'i')
		{
			scanf("%d", &value);
			insert(value);
		}
		else if (cmd[0] == 'd')
		{
			if (strlen(cmd) > 6)
			{
				if (cmd[6] == 'F')
				{
					deleteFirst();
				}
				else if (cmd[6] == 'L')
				{
					deleteLast();
				}
			}
			else
			{
				scanf("%d", &value);
				deleteKey(value);
			}
		}
	}

	printList();
	
	return 0;
}
