#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000001
typedef struct node* NP;

NP head,tail;

void insert(int);
void delete(int,NP);
NP find(int);
void list();
NP makenode(int,NP);
void deletelast();
struct node{
	int num;
	NP next;
	NP pre;
};

int main(){
	head=malloc(sizeof(struct node));
	tail=malloc(sizeof(struct node));
	head->next=tail;
	tail->pre=head;
	int i;
	char com[12];
	int n,key;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%s",com);
		if(strcmp(com,"delete")==0){
			scanf("%d",&key);
			delete(key,NULL);
			//list();
		}
		else if(strcmp(com,"insert")==0){
			scanf("%d",&key);
			insert(key);
			//list();
		}
		else if(strcmp(com,"deleteFirst")==0){
			delete(head->next->num,head);
			//list();
		}
		else {
			deletelast();
			//list();
		}
		
	}
	
	list();
	return 0;
}

void insert(int k){
	NP new=makenode(k,head->next);
	new->pre=head;
	head->next=new;
	}


void delete(int k,NP x){
	if(x==NULL){
	NP del ,n = find(k);
	if(n==NULL)return;
	del=n->next;
	n->next=del->next;
	n->next->pre=n;
	free(del);
	}
	else {
		NP dele=x->next;
		x->next=dele->next;
		x->next->pre=x;
		free(dele);
	}
}

NP find(int k){
	NP n;
	for(n=head;n->next!=tail;n=n->next){
		if(n->next->num==k)return n;
	}
	return NULL;
}

void list(){
	NP n;
	for(n=head->next;n!=tail;n=n->next){
		if(n->next!=tail)printf("%d ",n->num);
		else printf("%d\n",n->num);
	}
}

NP makenode(int k,NP n){
	NP new;
	new=malloc(sizeof(struct node));
	new->num=k;
	new->next=n;
	n->pre=new;
	return new;
}

void deletelast(){
	delete(0,tail->pre->pre);
	
}
