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


//node
typedef struct DATA{
  int key;
  struct DATA *prev;
  struct DATA *next;
}DATA;


//prototype
void insert(int);
void delete(DATA *);
void print_node(void);


//head set
DATA *head,*tail;


int main(){
  int num, key, i;
  char com[15];
  DATA *dp;
  
  //create head
  head=(DATA *)malloc(sizeof(DATA));
  head->next=NULL;
  head->prev=NULL;

  //input num
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    
    //input command
    scanf("%s",com);
      
    //insert data
    if(strcmp(com,"insert")==0){
      //input key
      scanf("%d",&key);
      
      insert(key);
    }

    //delete data
    else if(strcmp(com,"delete")==0){
      //input key
      scanf("%d",&key);

      for(dp=head->next;dp!=NULL;dp=dp->next){
	if(dp->key==key) {
	  delete(dp);
	  break;
	}
      }
    }

    //deleteFirst
    else if(strcmp(com,"deleteFirst")==0) delete(head->next);

    //deleteLast
    else if(strcmp(com,"deleteLast")==0) delete(tail);
    
    //command error
    else printf("ERROR:command\n");

     
  }

  //output node
  print_node();

  free(head);
  return 0;
}


//insert to next head
void insert(int key){
  DATA *data;
  
  data=(DATA *)malloc(sizeof(DATA));

  if(data==NULL) return;

  data->key=key;
  
  data->next=head->next;
  if(data->next!=NULL)data->next->prev=data;
  else tail=data;
  head->next=data;
  data->prev=head;

}


//delete DATA *
void delete(DATA *dp){
  
  dp->prev->next=dp->next;
  if(dp->next!=NULL)  dp->next->prev=dp->prev;
  else  tail=dp->prev;

  free(dp);
}


//output node
void print_node(void){
  DATA *dp;

  for(dp=head->next;dp->next!=NULL;dp=dp->next){
    printf("%d ",dp->key);
  }
  printf("%d\n",dp->key);
}

