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

struct list {
	int value;
	struct list *front;
	struct list *back;
};

int main(void)
{
	int max_order				= 0;
	char str[256]				= {};
	int i 						= 0;
	int j						= 0;
	struct list List[1000000]	= {};
	struct list *First			= NULL;
	struct list *Last			= &List[0];
	struct list *tmp			= NULL;
	struct list *tmp1			= NULL;
	struct list *tmp2			= NULL;
	int num						= 0;
	int cmp						= 0;
	fgets( str, 256, stdin );
	max_order = atoi(&str[0]);
	
	//printf("%d\n", max_order);
	
	for ( j = 0; j < max_order; j++ ) {
		fgets( str, 256, stdin );
		for ( i = 0; str[i] != ' ' && str[i] != '\0'; i++ ) {
		}
		str[i] = '\0';
		//printf("%s\n", str);
		
		if ( strcmp( str, "insert" ) == 0 ) {
			List[num].value = atoi(&str[i+1]);
			List[num].back = First;
			List[num].front = NULL;
			if ( First != NULL ) {
			    First->front = &List[num];
			}
			First = &List[num];
			/*if ( First -> back != NULL && First -> back -> front != NULL) {
			printf("value:%d value_:%d value__:%d\n", First->value, 
			First -> back -> value, First -> back -> front -> value);
			}*/
			num++;
			//printf("%d\n", num);
		}
		
		if ( strcmp( str, "delete" ) == 0 ) {
			tmp = First;
			cmp = atoi(&str[i+1]);
			//printf("%d %d\n", cmp, tmp -> back -> value);
			
			while ( tmp != NULL ) {
				if ( tmp  -> value == cmp ) {
					tmp1 = tmp -> front;
					tmp2 = tmp -> back;
					tmp1 -> back = tmp -> back;
					if ( tmp2 != NULL ) {
    					tmp2 -> front = tmp -> front;
					} else {
					    Last = tmp1;
					}

					break;
				}
				tmp = tmp -> back;
			}
			
		}
		
		if ( strcmp( str, "deleteFirst" ) == 0 ) {
			tmp = First -> back;
			tmp -> front = NULL;
			First = tmp;
		}
		
		if ( strcmp( str, "deleteLast" ) == 0 ) {
			tmp = Last -> front;
			tmp -> back = NULL;
			Last = tmp;
		}
		
	}
	
	tmp = First;

	while ( tmp != NULL ) {
	    printf("%d ", tmp->value);
	    tmp = tmp -> back;
	}
	
	
	
	
	
	return 0;
}
