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


struct node{
  int key;
  struct node *next;
  struct node *prev;
};



typedef struct node *NodePointer;

NodePointer nil;




void init(){

  nil=(NodePointer)malloc(sizeof(struct node));

  nil->next=nil;
  nil->prev=nil;

}


NodePointer Search(int key){

  NodePointer a=nil->next;

  while(a != nil && a->key != key){

    a=a->next;
  }


  return a;
}



void Output(){
  
  NodePointer a=nil->next;
  
  int count=0;
  
  
  
  while(1){
    
    if(a==nil){break;}
    
    if(count==0){printf("%d",a->key);}
    else{printf(" %d",a->key);}
    
    
    count++;
    a=a->next;
    
  }
  
  printf("\n");
  
}





void deleteNodePointer(NodePointer a){
  if(a==nil){return ;}

  a->prev ->next=a->next;
  a->next ->prev=a->prev;

  free(a);

}




void deleteFirst(){

  deleteNodePointer(nil->next);
}





void deleteLast(){
  deleteNodePointer(nil->prev);

}





void deleteKey(int a){
  deleteNodePointer(Search(a));

}





void insertKey(int key){

  NodePointer a=(NodePointer )malloc(sizeof(NodePointer));

  a->key=key;


  a->next=nil->next;

  nil->next->prev=a;

  nil->next=a;
  a->prev=nil;
  
}


int main(){

  int number;
  scanf("%d",&number);

  int i;

  
  char com[20];
  int key;
  
  init();

  
  for ( i = 0; i < number; i++ ){
    scanf("%s%d", com, &key);

    if ( com[0] == 'i' ) {
      insertKey(key);
    }

    
    else  {
      //printf("now deletekey\n")
      if(strlen(com)==6){deleteKey(key);}
      
      
      else {


	
	if ( com[6] == 'F'){
	  //printf("now deleteFirst\n");
	  deleteFirst();
	}


	else if ( com[6] == 'L' ) {
	  deleteLast();
	  //printf("now deleteLast\n");
	}
	
	
      }
    }
  }


  
  Output();
  return 0;
}


