#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct DuLNode
{
	int data;
	struct DuLNode *prior,*next;	
}DuLNode;

DuLNode *InitDuLNode()
{
	DuLNode *h=(DuLNode*)malloc(sizeof(DuLNode));
	h->prior=h->next=h;
	return h;	
}

void insert(int key,DuLNode *h)
{
	DuLNode *p=(DuLNode*)malloc(sizeof(DuLNode));
	p->data=key;
	p->next=h->next;
	h->next->prior=p;
	h->next=p;
	p->prior=h;	
}
void Delete(int key,DuLNode *h)
{
	DuLNode *p=h->next; 
	if(h->prior==h)
	return;
	while(p!=h)
	if(p->data==key)
	{
		p->prior->next=p->next;
		p->next->prior=p->prior;
		free(p);
		break;
	}
	else
	p=p->next;			
}

void deleteFirst(int key,DuLNode *h)
{
	if(h->prior==h)
	return;
	h->next=h->next->next;
	h->next->next->prior=h;
} 

void deleteLast(int key,DuLNode *h)
{
	if(h->prior==h)
	return;
	h->prior->prior->next=h;
	h->prior=h->prior->prior;
}
int main(int argc, char *argv[])
{
	DuLNode *h,*p;
	int n,i,key;
	char a[15];
	scanf("%d",&n);
	h=InitDuLNode();	
	for(i=0;i<n;i++)
	{
		scanf("%s%d",a,&key);
		if(strcmp(a,"insert")==0)
		insert(key,h);		
		else if(strcmp(a,"delete")==0)
		Delete(key,h);
		else if(strcmp(a,"deleteFirst")==0)
		deleteFirst(key,h);
		else
		deleteLast(key,h);
		
	}
	p=h->next;
	while(p!=h)
	{
		printf("%d",p->data);
		p=p->next;
		if(p!=h)
		printf(" ");
	}
	printf("\n");
	return 0;
}