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

#define MAXLEN 1000000

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

int ghead, gtail, gemhead, gemtail, gcnt;
struct sDLL list[MAXLEN+1];

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

   	if( 0 == strcmp( "insert", command ) ) {
   		pre=ghead;
		if( gcnt <= (ghead+1) && gcnt < MAXLEN ) {
			ghead=gcnt++;
		} else {
			ghead=gemhead;
			gemhead=list[gemhead].next;
			 if( -1 == gemhead ) {
				gemtail=-1;
			}
		}
		
		if( -1 == pre ) {
   			gtail=0;		
		} else {
   			list[pre].pre=ghead;
   		}
   		list[ghead].key=key;
		list[ghead].pre=-1;
		list[ghead].next=pre;

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

	return;
}   	

int main( void ) 
{
    int i;
    int n;
    char command[12];
    int key;
     
    scanf( "%d", &n );
    gemhead=gemtail=ghead=gtail=-1;
    gcnt=0;
    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 != i ) {
      	printf( "%d", list[i].key );
       	if( gtail == i ) {
     		printf( "\n" );
     		break;
     	} else {
     		printf( " " );
     	}
     	i=list[i].next;
     }

    return 0;
}