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

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

void insert(int); //?????????????´???????
void delete(Node *);  //?????????????????¢?????¬????????????????????????
Node *search(int);  //???????????????key?????????????´??????¢????????????????????¢?????¬????????????

Node *nil; //????????????????????????

main(){
	int n,tmpKey,i;
	char tmpStr[12];
	Node *p;
	
	//??????
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil->prev = nil;

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", tmpStr);
		if (strcmp(tmpStr, "insert") == 0){
			scanf("%d", &tmpKey);
			insert(tmpKey);
		}
		else if (strcmp(tmpStr, "delete") == 0){
			scanf("%d", &tmpKey);
			delete(search(tmpKey));
		}
		else if (strcmp(tmpStr, "deleteFirst") == 0) delete(nil->next);
		else if (strcmp(tmpStr, "deleteLast") == 0) delete(nil->prev);
	}

	for (p = nil->next; p->next != nil; p = p->next){
		printf("%d ", p->key);
	}
	printf("%d\n", p->key);

	return 0;
}

void insert(int key){ //?????????????´???????
	Node *new;
	//printf("-- insert %d\n", key);

	new = (Node *)malloc(sizeof(Node));
	new->key = key;
	new->next = nil->next;
	new->prev = nil;
	nil->next = new;
	new->next->prev = new;

}

void delete(Node *ad){  //?????????????????¢?????¬????????????????????????
	if (ad == NULL){
		//printf("-- delete NULL\n");
		return;
	}
	//printf("-- delete %p\n", ad);
	ad->prev->next = ad->next;
	ad->next->prev = ad->prev;
	free(ad);
}

Node *search(int key){  //???????????????key?????????????´??????¢????????????????????¢?????¬????????????
	Node *find;
	//printf("-- search %d\n", key);
	for (find = nil->next; find != nil; find = find->next){
		if (find->key == key) return find;
	}

	return NULL;
}