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

#define MAX 2000000

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

typedef struct node * NodePointer;

NodePointer make_1node(int,NodePointer);
void insert(int);
void delete(int);
NodePointer finditem(int);
void listprint(void);

NodePointer head,tail;

int main(){

  int kaisuu,suuzi,i;
  char meirei[11];
  NodePointer n,n1;

  scanf("%d",&kaisuu);

  //printf("wa-i\n");

  head = make_1node(0,NULL);

  tail = make_1node(0,NULL);

  head->next = tail;
  tail->prev = head;

  //printf("wa-i2\n");
  
  for(i=0;i<kaisuu;i++){
    
    scanf("%s",meirei);

    // printf("wa-i125\n");

    if(strcmp(meirei,"insert")==0||strcmp(meirei,"delete")==0){
      //printf("wa-i169\n");
      scanf("%d%*c",&suuzi);
      
    }

    //printf("inputString %s\n",meirei);
    
    if(strcmp(meirei,"insert")==0){
      
      insert(suuzi);
      // printf("wa-i6\n");
     
    }
    
    else{
      
      //printf("wa-i13\n");
      //printf("suuzi=%d\n",suuzi);
      if(strcmp(meirei,"deleteFirst")==0){
	suuzi=head->next->key;
	//printf("wa-i60\n");

      }
      if(strcmp(meirei,"deleteLast")==0){
	suuzi=tail->prev->key;
	//printf("wa-i50\n");
      }
      delete(suuzi);
      
    }
    
    
    /* for(n=head;n!=head;n=n->next){
       
    //if(n==head)printf("wa-i\n");
    if(n->next==head)printf("%d\n",n->key);
    else printf("%p \n",&n->key);
    
    
    // printf("i=%d\n",i);
    }*/
    
  }

  //printf("wa-i30\n");
  listprint();
  
  return 0;
}

NodePointer make_1node(int keydata,NodePointer p){
    
  NodePointer n;

  //printf("wa-i3\n");
  
  if((n=(NodePointer)malloc(sizeof(struct node)))==NULL){
    printf("Error in memory allocation\n");
    exit(8);
  }

  //printf("wa-i4\n");

  // if(p==NULL){

  //printf("wa-i8\n");
    
  n->next = NULL;
  n->prev=NULL;
  n->key=keydata;

  /* }
     else {

     //printf("wa-i7\n");
    
     p->next = n->next;
     // p->next->prev=n;
     // p->next=n;
     n->prev=p;
     n->key=keydata;

    
     }*/

  //printf("wa-i5\n");
  
  return n;

}

void insert(int keydata){

  NodePointer newnode,n;
  //static int count=0;

  //printf("wa-i\n");
  
  newnode=make_1node(keydata,head);

  
  
  //printf("wa-i9\n");
  //printf("%d\n",newnode->key);
  
  newnode->next=head->next;

  
  // printf("%d",head->next->key);

  // printf("wa-i11\n");

  //printf("%p\n",&newnode->next);
  
  //head->next=newnode;

  // printf("wa-i12\n");

  
  head->next=newnode;
  //printf("wa-i40\n");
  //printf("Head Next key : %d\n", head->next->key); 
  //printf("yeeei11\n");
  newnode->prev=head;
  newnode->next->prev=newnode;
    
  //printf("wa-i10\n");

  //if(count!=0)printf("%d\n",head->next->next->key);
  
  // count++;

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

  
  
  /* for(n=head->next;n!=head;n=n->next){
    
     if(n->next==head)printf("%d\n",n->key);
     else printf("%d ",n->key);
  */
    
}
  
  


void delete(int keydata){

  NodePointer n;

  // printf("wa-i14\n");


  
  if((n=finditem(keydata))!=NULL){
    // printf("delete :%d\n",n->key);

    
    n->prev->next = n->next;
    
    if(n->next!=NULL) n->next->prev=n->prev;
  }

  // printf("wa-i15\n");

  free(n);

}

NodePointer finditem(int value){

  NodePointer n;

  //printf("value=%d\n",value);

  for(n=head;n->next!=NULL;n=n->next){
    //printf("%d\n",n->key);
    if(n->next->key == value)return n->next;
    // printf("wa-i16\n");
  }
  //printf("wa-i15\n");
  return NULL;
}

void listprint(){

  NodePointer n;

  for(n=head->next;n->next!=NULL;n=n->next){

    if(n->next->next==NULL)printf("%d\n",n->key);
    else printf("%d ",n->key);

  }
}