#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list{
	int key;
	struct list *next ;
}list;

list* insert(list* h,int k){
	list* x;
	x = (list*)malloc(sizeof(list));
	x->next = h;
	x->key = k;
//	printf("insert\n");
	return x;
}

void delete(list* h,int k){
	list* x;
//	list* t;
	list* ins;
	x = h;
//	printf("delete\n");
	if(h->key==k){
		h = h->next;
		ins = x;
		free(ins);
		return;
	}
	while(x->next!=NULL){
		if((x->next)->key==k){
			ins = x->next;
			x->next = ins->next;
			free(ins);
			return;
		}else{
			x = x->next;
		}
	}
	return;
}

list* deleteFirst(list* h){
	list* ins;
	ins = h;
	h = h->next;
	free(ins);
	return h;
}

void deleteLast(list* h){
	list* x;
	list* ins;
	x = h;
	if(h->next==NULL){
		ins = h;
		h = ins->next;
		free(ins);
		return;
	}

	while((x->next)->next!=NULL){
		x = x->next;
	}

	ins = x->next;	
	x->next = NULL;
	free(ins);
	return;
}

int main(int argc, char argv[]){
	int n;
	char command[20] = "\0";
	int d;
	list* head;
	list* x;
	head = NULL;

	scanf("%d",&n);

	int i;
	for(i=0;i<n;i++){
		scanf("%s %d",command,&d);
		if(!strcmp(command,"insert"))head = insert(head,d);
		else if(!strcmp(command,"delete"))delete(head,d);
		else if(!strcmp(command,"deleteFirst"))head = deleteFirst(head);
		else if(!strcmp(command,"deleteLast"))deleteLast(head);
		else printf("The command does not exist.\n");
//		printf("%s %d\n",command,d);
	}

	x = head;
	if(x!=NULL)printf("%d",x->key);
	x = x->next;
	while(x != NULL){
		printf(" ");
		printf("%d",x->key);
		x = x->next;
	}

	return 0;
}