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

typedef struct lis{
	int Key;
	struct lis* last;
	struct lis* next;
}List;

typedef struct ma{
	struct lis* top;
	struct lis* back;
}MainData;

void Delete(MainData* mai,struct lis *p){
	if(p->next == NULL){
		mai->back = p->last;
	}else{
		(p->next)->last = p->last;
	}
	if(p->last == NULL){
		mai->top = p->next;
	}else{
		(p->last)->next = p->next;
	}
	free(p);
}

int main() {
	
	MainData mai;
	int n;
	char valch[10];
	int valin;
	mai.top = NULL;
	mai.back = NULL;
	
//	printf("val(n) => ");
	scanf("%d",&n);
	
//	printf("loopstart\n");
	for(int i = 0; i < n; i++){
		scanf("%s", valch);
		
		if(strcmp(valch,"insert") == 0){
			scanf("%d",&valin);
			//導入
			struct lis *p;
			if ((p = (struct lis *) malloc(sizeof(struct lis))) == NULL) {
				break;
			}
			p->Key = valin;
			p->next = mai.top;
			
			p->last = NULL;
			if(mai.top != NULL){
				mai.top->last = p;
			}
			mai.top = p;
			if(mai.back == NULL){
				mai.back = p;
			}
		}else if(strcmp(valch,"delete") == 0){
			scanf("%d",&valin);
			//探す
			for(struct lis *p = mai.top;p != NULL; p = p->next){
				if(p->Key == valin){
					Delete(&mai,p);
					break;
				}
			}
		}else if(strcmp(valch,"deleteFirst") == 0){
			if(mai.top != NULL){
				Delete(&mai,mai.top);
			}
		}else if(strcmp(valch,"deleteLast") == 0){
			if(mai.back != NULL){
				Delete(&mai,mai.back);
			}
		}
		
		
/*		printf("%dth result : ",i);
		for(struct lis *p = mai.top;p != NULL; p = p->next){
			printf(" %d",p->Key);
			if(p->last != NULL){
				printf("(o,");
			}else{
				printf("(-,");
			}
			if(p->next != NULL){
				printf("o)");
			}else{
				printf("-)");
			}
			
		}
		printf("\n");*/
	}
	int checker = 0;
//	printf("result?\n");
	for(struct lis *p = mai.top;p != NULL; p = p->next){
//		printf("result\n");
		if(checker == 0){
			checker++;
		}else{
			printf(" ");
		}
		printf("%d",p->Key);
	}
	printf("\n");
	return 0;
}

