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

typedef struct t_node T_NODE;
struct t_node {
	int key;
	T_NODE *next;
	T_NODE *prev;
};

T_NODE *newT_NODE() {
	T_NODE *newT_Node;
	newT_Node = (T_NODE *)malloc(sizeof(T_NODE));
	if( newT_Node == NULL) {
		exit(1);
	}
	newT_Node->next = NULL;
	newT_Node->prev = NULL;
	
	return newT_Node;
}

T_NODE *insert_x(T_NODE *list, int x)
{
	T_NODE *newT_Node	= newT_NODE();
	newT_Node->key		= x;
	if( list != NULL ) {
		newT_Node->next		= list;
		newT_Node->prev		= list->prev;
		
		list->prev = newT_Node;
	}
	else {
		newT_Node->next = NULL;
		newT_Node->prev = newT_Node;
	}
	
	return newT_Node;
}

T_NODE *delete_x(T_NODE *list, int x)
{
	T_NODE *p = list->next;
	T_NODE *tmp;
	
	if( list->key == x ) {
		if( list->prev == list ) {
			free(list);
			return NULL;
		}
		list->next->prev = list->prev;
		return list->next;
	}
	
	
	while( p != NULL ) {
		if( p->key == x ) {
			tmp = p->prev;
			if( p->next != NULL )
				p->next->prev	= tmp;
			else
				list->prev = tmp;
				
			tmp->next = p->next;
			free(p);
			break;
		}
		p = p->next;
	}
	return list;
}

T_NODE *deleteFirst(T_NODE *list)
{
	if( list == NULL ) {
		return list;
	}
	if( list->prev == list ) {
		free(list);
		return NULL;
	}
	
	T_NODE *tmp = list->next;
	tmp->prev = list->prev;
	free(list);
	
	return tmp;
}

T_NODE *deleteLast(T_NODE *list)
{
	if( list == NULL ) {
		return list;
	}
	if( list->prev == list ) {
		free(list);
		return NULL;
	}
	
	T_NODE *Last = list->prev;
	Last->prev->next = NULL;
	list->prev = Last->prev;
	free(Last);
	
	return list;
}

void showList(T_NODE *list)
{
	while(list != NULL) {
		printf("%d ", list->key);
		list = list->next;
	}
	putchar('\n');
}
	

int main()
{
	T_NODE *list = NULL;
	int i;
	int n;
	
	char str[32];
	
	int x=0;
	char cmd[16];
	
	scanf("%d\n", &n);
	
	for(i=0; i<n; i++)
	{
		fgets(str, 32, stdin);
		if( strstr(str, " ") != NULL )
			sscanf(str, "%s %d", cmd, &x);
		else
			sscanf(str, "%s", cmd);
			
		
		if( !strcmp(cmd, "insert") ) {
			list = insert_x(list, x);
			//~ printf("### ");
			//~ showList(list);
		}
		else if( !strcmp(cmd, "delete") ) {
			list = delete_x(list, x);
			//~ printf("### ");
			//~ showList(list);
		}
		else if( !strcmp(cmd, "deleteFirst") ) {
			list = deleteFirst(list);
			//~ printf("### ");
			//~ showList(list);
		}
		else if( !strcmp(cmd, "deleteLast") ) {
			list = deleteLast(list);
			//~ printf("### ");
			//~ showList(list);
		}
			
	}
	showList(list);
	
	return 0;
}