#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  int key;
  struct node *pref;
  struct node *next;

};
typedef struct node * NP;
NP head;
void init();
NP insert(int);
void delete(int);
void deleteFirst();
void deleteLast();
NP make1_node(int,NP,NP);
void show();
int main(){
  int n,i,j,num;
  char str[12];
  init();

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert")==0){
      scanf("%d",&num);
      insert(num);
    }
    else if(strcmp(str,"delete")==0){

     scanf("%d",&num);
      delete(num);
    }
    else if(strcmp(str,"deleteFirst")==0)
      deleteFirst();
    else if(strcmp(str,"deleteLast")==0)
      deleteLast();
  }

  show();
  return 0;
}
NP make1_node(int key,NP pre,NP next){
  NP newnode;
  if((newnode=(NP)malloc(sizeof(struct node)))==NULL){
    printf("Error:Memory Over\n");
    exit(0);
  }
  newnode->key=key;
  newnode->pref=pre;
  newnode->next=next;
  newnode->next->pref=newnode;
  ///////////////////koko ni henkou ireru
  return newnode;
}
NP insert(int key){
  NP newnode;
  static int flag=0;
  newnode=make1_node(key,head,head->next);
  head->next=newnode;
  if(flag++==0)
    head->pref=newnode;
  
  return newnode;
}
void delete(int key){
  NP p,q;
  for(p=head;p->next!=head;p=p->next){
    if(p->next->key==key){
      q=p->next;
      q->next->pref=p;
      p->next=q->next;
      free(q);
      return;
	}
      
  }

}
void deleteFirst(){
  NP q;
  q=head->next;
q->next->pref=head;
  head->next=q->next;

  free(q);
}
void deleteLast(){
  NP q;
   q=head->pref;
  head->pref=q->pref;
  q->pref->next=head;
  free(q);
}
void show(){
  NP p;
  int n=0;
  for(p=head->next;p!=head;p=p->next){
    if(n!=0)
      printf(" ");
    n++;
    printf("%d",p->key);
  }
  printf("\n");

}

void init(){
  head=malloc(sizeof(struct node));
  head->next=head;
  head->pref=head;
  

}

