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

struct Node
{
	int nKey;
	Node* pNext, *pPrev;
};

Node* pNul;

void Init()
{
	pNul = (Node*)malloc(sizeof(Node));
	pNul->pNext = pNul;
	pNul->pPrev = pNul;
}

void insert(int key)
{
	Node* pCur = (Node*)malloc(sizeof(Node));
	pCur->nKey = key;
	pCur->pNext = pNul->pNext;
	pCur->pNext->pPrev = pCur;
	//changed
	pCur->pPrev = pNul;
	pNul->pNext = pCur;
}

Node* listSearch(int key)
{
	Node* pCur = pNul->pNext;
	while (pCur->nKey != key && pCur->pNext != pNul)
	{
		pCur = pCur->pNext;
	}
	return pCur;
}

void printList()
{
	Node* pCur = pNul->pNext;
	int nIndex = 0;
	while (pCur != pNul)
	{
		if (0 != nIndex)
		{
			printf(" ");
		}
		printf("%d", pCur->nKey);
		++nIndex;
		pCur = pCur->pNext;
	}
	printf("\n");
}

void deleteNode(Node* p)
{
	p->pNext->pPrev = p->pPrev;
	p->pPrev->pNext = p->pNext;
	p->pNext = p;
	p->pPrev = p;
	free(p);
}

void deleteFirst()
{
	deleteNode(pNul->pNext);
}

void deleteLast()
{
	deleteNode(pNul->pPrev);
}

void deleteKey(int key)
{
	deleteNode(listSearch(key));
}

int main()
{
	char cod[20];
	int nkey, n;
	scanf("%d", &n);
	Init();
	for (int i = 0; i < n; ++i)
	{
		scanf("%s", cod);
		if ('i' == cod[0])
		{
			scanf("%d", &nkey);
			insert(nkey);
		}
		else if (6 < strlen(cod))
		{
			if ('L' == cod[6])
			{
				deleteLast();
			}
			else if ('F' == cod[6])
			{
				deleteFirst();
			}
		}
		else
		{
			scanf("%d", &nkey);
			deleteKey(nkey);
		}
	}
	printList();
	return 0;
}
