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

typedef struct node *link;
struct node{
	int v;
	link next;
	link prev;
};

link head=NULL;
link tail=NULL;

void insert(int v){
	link x = malloc(sizeof(*x));
	x->v = v; x->next=NULL; x->prev=NULL; 
	if(head==NULL){
		head=x; tail=x;
	}else{
		head->prev=x;
		x->next=head;
		head=x;
	}
}

link search(int v){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->v==v)return t;
	}
	return NULL;
}

void deleteFirst(){
	head=head->next;
	if(head==NULL){
		//free(tail);
		tail=NULL;
	}else head->prev=NULL;
}

void deleteLast(){
	tail=tail->prev;
	if(tail==NULL){
		//free(head);
		head=NULL;
	}else tail->next=NULL;
	
}

void delete(int v){
	link next,prev;
	link t=search(v);
	if(t==NULL)return;
	if(t==head)deleteFirst();
	else if(t==tail)deleteLast();
	else{
		next=t->next;
		prev=t->prev;
		next->prev=prev;
		prev->next=next;
		//t->prev->next=t->next;
		//t->next->prev=t->prev;
		free(t);
	}
}

void Print(){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->next==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}
void PrintR(){
	link t;
	for(t=tail;t!=NULL;t=t->prev){
		if(t->prev==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}

void FreeList(){
	link next;
	while(head->next!=NULL){
		next=head->next;
		free(head);
		head=next;
	}
}

int main(void){
	int n,i;
	char c[20];
	int x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",c);
		
		if(!strcmp(c,"insert")){
			scanf("%d",&x);
			insert(x);
		}else if(!strcmp(c,"delete")){
			scanf("%d",&x);
			delete(x);
		}else if(!strcmp(c,"deleteFirst")){
			deleteFirst();
		}else if(!strcmp(c,"deleteLast")){
			deleteLast();
		}
		//printf("head:%d\ntail:%d\n",head->v,tail->v);
		//Print();
		//PrintR();
	}
	Print();
	FreeList();
	return 0;
}