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

struct list{
  int key;
  struct list *next;
};

void insert(int x, struct list *p);
void dele(int x,struct list *p);
void deleteFirst(struct list *p);
void deleteLast(struct list *p);
void show_list(struct list *p);
void free_list(struct list *p);

int main(void){
  int i,j;
  int n;
  char command[12];
  int x=0;
  struct list *head;

  head=(struct list *) malloc(sizeof(struct list));
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(strcmp(command,"insert")==0){
      scanf("%d",&x);
      insert(x,head);
    }
    else if(strcmp(command,"delete")==0){
      scanf("%d",&x);
      dele(x,head);
    }
    else if(strcmp(command,"deleteFirst")==0) deleteFirst(head);
    else deleteLast(head);
  }


  show_list(head);
  free_list(head);
  return 0;
}
void show_list(struct list *p){
  p=p->next;
  if(p!=NULL){
    printf("%d",p->key);
    p=p->next;
  }
  while(p!=NULL){
    printf(" %d",p->key);
    p=p->next;
  }
  printf("\n");
}
void free_list(struct list *p){
  struct list *p2;
  while(p!=NULL){
    p2=p->next;
    free(p);
    p=p2;
  }
}
void insert(int x,struct list *p){
  struct list *p2;
  if((p2=(struct list *) malloc(sizeof(struct list))) == NULL){
      printf("malloc error\n");
  }
  p2->key=x;
  p2->next=p->next;
  p->next=p2;
}
void dele(int x,struct list *p){
  while(p!=NULL){
    if(p->next->key==x){
      free(p->next);
      p->next=p->next->next;
      break;
    }
    p=p->next;
  }
}
void deleteFirst(struct list *p){
  free(p->next);
  p->next=p->next->next;
}
void deleteLast(struct list *p){
  while(1){
    if(p->next==NULL) break;
    if(p->next->next==NULL){
      free(p->next);
      p->next=NULL;
      break;
    }
    p=p->next;
  }
}