#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node{
	struct node *prev;
	struct node *next;
	int key;
};
int n;
struct node *nil; //先頭

void insert(key);
void deletekey(key);
void deleteLast();
void deleteFirst();
struct node* listSearch(int);
void printList();
int main(void)
{
	int key;
	int i;
	char com[20];
	scanf("%d",&n);
	nil =(struct node *)malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
	for(i=0;i<n;i++){
		scanf("%s",com);

		if(com[0] == 'i'){
			scanf("%d",&key);
			insert(key);
		}
		if(com[0] == 'd'){
			if(com[6]=='F'){
				deleteFirst();
			}
			else if(com[6]=='L'){
				deleteLast();
			}
			else{
				scanf("%d",&key);
				deletekey(key);
			}
		}
		
	}
	printList();
	return 0;
}

void insert(int key){
	struct node *x;
	x = (struct node *)malloc(sizeof(struct node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

void printList(){
	int a=0;
	struct node *here;
	here = nil->next;
	while(1){
		if(here==nil) break;
		if(a++>0){
			printf(" ");
		}
		printf("%d",here->key);
		here = here->next;
	}
	printf("\n");
}

void deletekey(int key){
	struct node *bye;
	if(key == -1){
		bye = nil->next;
	}
	else if(key == -2){
		bye = nil->prev;
	}
	else{
		bye = listSearch(key);
	}
	if(bye == nil) return;
	bye->prev->next = bye->next;
	bye->next->prev = bye->prev;
	free(bye);
}

struct node* listSearch(int key){
	struct node *here;
	here = nil->next;
	while(key!=here->key && here!=nil){
		here = here->next;
	}
	return here;
}

void deleteFirst(){
	deletekey(-1);
}
void deleteLast(){
	deletekey(-2);
}
