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

struct Node{
	int key;
	struct Node *prev, *next;
};

struct Node *nil;

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

struct Node* listSearch(int k){
	struct Node *cur = nil->next;
	while(cur != nil && cur->key != k){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(struct Node *x){
	if(x == nil)return;
	x->prev->next = x->next;
	x->next->prev = x->prev;
	free(x);
}

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

void delete(int k){
	deleteNode(listSearch(k));
}

void PrintList(){
	struct Node *cur = nil->next;
	int i;
	while(1){
		if(cur == nil){
			break;
		}
		if(i++ > 0){
			printf(" ");
		}
		printf("%d",cur->key);
		cur = cur ->next;
	}
	printf("\n");
}

int main(void){
	int n,d,i;
	char order[20];
	init();
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",order,&d);
		if((strcmp(order,"insert"))==0){
			insert(d);
		}else if((strcmp(order,"delete"))==0){
			delete(d);
		}else if((strcmp(order,"deleteFirst"))==0){
			deleteNode(nil->next);
		}else if((strcmp(order,"deleteLast"))==0){
			deleteNode(nil->prev);
		}
	}
	PrintList();
	return 0;
}
