#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] != ' '; i++ ) {
		    if ( str[i] == '\r' || str[i] == '\n') {
		        break;
		    }
		}
		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];
			} else {
			    Last = &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;
					if ( tmp1 != NULL ) {
    					tmp1 -> back = tmp -> back;
					} else {
					    First = tmp2;
					}
					if ( tmp2 != NULL ) {
    					tmp2 -> front = tmp -> front;
					} else {
					    Last = tmp1;
					}

					break;
				}
				tmp = tmp -> back;
			}
			
		}
		
		if ( strcmp( str, "deleteFirst" ) == 0 ) {
			tmp = First -> back;
			if ( tmp != NULL ) {
    			tmp -> front = NULL;
			} else {
			    Last = tmp;
			}
			First = tmp;
			//printf("%d\n", Last -> front);
			//printf("aa\n");
		}
		
		if ( strcmp( str, "deleteLast" ) == 0 ) {
			tmp = Last -> front;
			if ( tmp != NULL) {
    			tmp -> back = NULL;
    			//printf("aa\n");
			} else {
			    First = tmp;
			}
			Last = tmp;
		}
		
	}
	
	tmp = First;
	//printf("%d\n\n", tmp -> value);

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