#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 struct node{
	int key;
	struct node *prev;
	struct node *next;
};
typedef struct node * NodePoineter;

NodePoineter nil;

NodePoineter listSearch(int key){
	NodePoineter p;
	int i;
	p=nil->next;

	while((p!=nil)&&(p->key!=key)){
		p=p->next;
	}
	return p;
}

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

void printList(){
	NodePoineter cur =nil->next;
	int isf=1;
	while(1){
		if(cur == nil) break;
		if(isf == 0) printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
		isf=0;
	}
	printf("\n");
}

void deleteNode(NodePoineter t){
	t->prev->next=t->next;
	t->next->prev=t->prev;
}

void deleteFirst(){
	NodePoineter t = nil->next;
	if(t==nil) return;
	deleteNode(t);
}

void deleteLast(){
	NodePoineter t = nil->prev;
	if(t==nil) return;
	deleteNode(t);
}

void delete(int key){
	NodePoineter t;
	if((t=listSearch(key))!=NULL){
		if(t==nil) return;
		deleteNode(t);
	}
}

void insert(int key){
	NodePoineter n;
	n=malloc(sizeof(struct node));
	n->key=key;
	n->next=nil->next;

	nil->next->prev=n;
	nil->next=n;
	n->prev=nil;
}

int main(){
	int i,n,m,key;
	char command[12];
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s",command);
		if(strcmp(command,"insert")==0){
			scanf("%d",&key);
			insert(key);
		}else if(strcmp(command,"delete")==0){
			scanf("%d",&key);
			delete(key);
		}else if(strcmp(command,"deleteFirst")==0){
			deleteFirst();
		}else{
			deleteLast();
		}
	}

	printList();
	return 0;
}