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

struct node{
	int key;
	struct node *next;
	struct node *prev;
};

struct node *null;

struct node *listSearch(int key)
{
	struct node *cur = null->next;
	while(cur!=null&&cur->key!=key)
	{
		cur =cur->next;
	}
	return cur;
}

void init(){
	
	null=(struct node*)malloc(sizeof(struct node));
	null->next=null;
	null->prev=null;
}

void printList()
{
	struct node *cur=null->next;
	int isf=0;
	while(cur!=null)
	{
		if(isf++)putchar_unlocked(' ');
		printf("%d",cur->key);
		cur=cur->next;
	}
	putchar_unlocked('\n');
}

void deleteNode(struct node *t)
{
if(t==null) return;
t->prev->next=t->next;
t->next->prev=t->prev;
free(t);
}
void deleteFirst()
{
	deleteNode(null->next);
}
void deleteLast()
{
	deleteNode(null->prev);
}
void deleteKey(int key)
{
	deleteNode(listSearch(key));
}

void insert(int key)
{
	struct node *x=(struct node*)malloc(sizeof(struct node));
	x->key=key;
	x->next=null->next;
	null->next->prev=x;
	null->next=x;
	x->prev=null;
}
int main(void)
{
	int key,n,i;
	char com[20];
	null=(struct node*)malloc(sizeof(struct node));
	null->next=null;
	null->prev=null;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%s",com);
		if(strlen(com)>6)
		{
			if(com[6]=='F')
			{
				deleteFirst();
			}
			else
			{
				deleteLast();
			}
		}
		else
		{
			scanf("%d",&key);
			
			if(com[0]=='d')
				{
					deleteKey(key);
				}
			else
			{
				insert(key);
			}
			
		}
	}
	printList();
	return 0;
}


	

