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


typedef struct data_t{
	int key;
	struct data_t *prev;
	struct data_t *next;
}DATA_T;


DATA_T HEAD;


void Insert(int key){

	DATA_T *p;


	if( (p = (DATA_T *)malloc(sizeof(DATA_T))) == NULL){
		printf("malloc error\n");
		exit(1);
	}

	p->key = key;
	p->prev = &HEAD;
	p->next = HEAD.next;
	HEAD.next->prev = p;
	HEAD.next = p;
}


void Delete(int key)
{
	DATA_T *p;

	for(p = HEAD.next; p != &HEAD; p = p->next){
		if(p->key == key){
			p->prev->next = p->next;
			p->next->prev = p->prev;
			free(p);
			break;
		}
	}
}


// 0:First 1:Last
void Delete_pos(int pos)
{
	DATA_T *p;

	if(pos == 1){
		p = HEAD.prev;
		HEAD.prev = p->prev;
		p->prev->next = &HEAD;
	}else{
		p = HEAD.next;
		HEAD.next = p->next;
		p->next->prev = &HEAD;
	}
	free(p);
}


int main()
{
	char in_str[30];
	DATA_T *p;
	char command[20];
	int key;
	int n;
	int i;


	fgets(in_str, sizeof(in_str), stdin);
	sscanf(in_str, "%d", &n);

	HEAD.next = &HEAD;
	HEAD.prev = &HEAD;

	for(i = 0; i < n; i++){
		fgets(in_str, sizeof(in_str), stdin);
		sscanf(in_str, "%s %d", command, &key);

		if(!strcmp(command, "insert")){
			Insert(key);
		}else if(!strcmp(command, "delete")){
			Delete(key);
		}else if(!strcmp(command, "deleteFirst")){
			Delete_pos(0);
		}else if(!strcmp(command, "deleteLast")){
			Delete_pos(1);
		}
	}


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

	return 0;
}
