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

struct sDLL {
    int key;
    int pre;
    int next;
};

int ghead, gtail;
struct sDLL list[1000001];

void dllOperation( char *command, int key )
{
	int i;
	int pre,tmp;

   	if( 0 == strcmp( "insert", command ) ) {
   		tmp=ghead;
		list[ghead].pre=ghead+1;
   		ghead++;
   		list[ghead].key=key;
		list[ghead].pre=-1;
		list[ghead].next=tmp;
   	} else if( 0 == strcmp( "delete", command ) ) {
   		i=ghead;
	   	while( 1 ) {
	   		if( key == list[i].key ) {
	   			if( ghead == i ) {
	   				ghead = list[i].next;
			   		list[ghead].pre=-1;	
	   			} else if( gtail == i ) {
	   				gtail = pre;
	   				list[gtail].next=pre;
	   			} else {
	   				list[pre].next = list[i].next;
	   				list[ list[i].next ].pre=list[i].pre;
	   			}
	   			list[i].key=-1;
	   			break;
	   		}
	   		pre=i;
	   		i=list[i].next;
	   	}

   	} else if( 0 == strcmp( "deleteFirst", command ) ) {
   		list[ghead].key=-1;
   		ghead=list[ghead].next;
   		list[ghead].pre=-1;	
   	} else {
		list[gtail].key=-1;  	
		tmp=list[gtail].next;
   		gtail=list[gtail].pre;
   		list[gtail].next=tmp;
   	}
   	
	return;
}   	

int main( void ) 
{

    int i;
    int n;
    char command[12];
    int key;
     
    scanf( "%d", &n );
    ghead=gtail=0;
    list[ghead].pre=-1;
    list[ghead].next=1;
    list[gtail].pre=0;
    list[gtail].next=1;
    ghead=-1;
    for( i=0; i<n; i++ ) {
        scanf( "%s", command );
        if( 0 == strcmp( "deleteFirst", command ) ) {
        	key=0;        
        } else if( 0 == strcmp( "deleteLast", command ) ) {
        	key=0;
        } else {
        	scanf( "%d", &key );
        }
        dllOperation( command, key );
    }

    i=ghead;
    while( 1 ) {
     	printf( "%d", list[i].key );
     	if( gtail == i ) {
     		printf( "\n" );
     		break;
     	} else {
     		printf( " " );
     	}
     	i=list[i].next;
     }

    return 0;
}