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

typedef struct DATA{
	int data;
	struct DATA *next;
	struct DATA *before;
}DATA, *link;

link setList(link h){
	h = (link)malloc(sizeof(struct DATA));
	h->next = NULL;
	h->next = NULL;
	h->data = -1;
	return h;
}
link insert(link h,int key){
	link x = (link)malloc(sizeof(struct DATA));
	//?????\??????????´?x?????????????????????
	x->data = key;
	x->before = h;
	if(h->next!=NULL)x->next = h->next;
	else x->next = NULL;
	
	//x????¬????????´?????????????????????????
	if(h->next!=NULL)h->next->before = x;
	
	//h?????¢???????????????
	h->next = x;
	
	
	return h;
}
link delete(link h,int data){//data?????????????????????
	link t = h;
	while(t->next != NULL){
		if(t->next->data == data){			
			t = t->next;
			t->before->next = t->next;
			if(t->next!=NULL)
				t->next->before = t->before;
			free(t);
			break;
		}
		t = t->next;
	}
	return h;
}
link deleteFirst(link h){//
	link t = h->next;
	h->next = t->next;
	t->next->before = h;
	free(t);
	return h;
}
link deleteLast(link h){
	link b,t;
	if(h->next==NULL)return h;
	t = h;
	while(t->next != NULL)t = t->next;
	t->before->next = NULL;
	free(t);
	return h;
}
link deleteAll(link h){
	link t;
	while (h->next != NULL){
		t = h->next;
		h->next = t->next;
		free(t);
	}
	return h;
}
void deleteList(link h){
	deleteAll(h);
	free(h);
	return;
}
void printList(link h){
	link t = h;
	//printf("List->:\n\t");
	while(t->next!=NULL){
		if(t->next->next==NULL)printf("%d\n",t->next->data);
		else printf("%d ",t->next->data);
		//printf("thisdata:%d beforedata:%d\n\t",t->next->data,t->next->before->data);
		if(t->next!=NULL)t = t->next;
	}
	printf("\n");
	return;
}



int main(){
	int i,n,num;
	char command[15];
	link head;
	
	scanf("%d",&n);
	
	head = setList(head);
	for(i=0;i<n;i++){
		scanf("%s",&command);
		if(strcmp(command,"insert") == 0){
			scanf("%d",&num);
			head = insert(head,num);
		}else if(strcmp(command,"delete") == 0){
			scanf("%d",&num);
			head = delete(head,num);
		}else if(strcmp(command,"deleteFirst")==0){
			head = deleteFirst(head);
		}else if(strcmp(command,"deleteLast") == 0){
			head = deleteLast(head);
		}
		//printList(head);
	}
	
	printList(head);
	
	//??????????????????
	deleteList(head);
	return 0;
}