#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node *link;
struct node{int n;  link next; link prev;};
link setLink(link p, link q, int n){
  link x = malloc(sizeof(struct node));
  x->n = n;  x->next = p; x->prev = q;
  if(p!=NULL) p->prev = x;
  return x; 
}

int main(void){
  link head, tail, p, q;
  int n, i, x;
  tail = setLink(NULL, NULL, -1);
  head = setLink(tail, NULL, -1);
  //if(head==tail->prev) printf("same\n");
  //else printf("false\n");
  //head->next = tail; tail->prev = head;
  char com[20];
  char list[4][20] = {"insert", "delete", "deleteFirst", "deleteLast"};
  
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s", com);
    //printf("%s",com);
    if(strcmp(com, list[0])==0){
      scanf("%d",&x);
      head->next = setLink(head->next, head, x);
    }
    else if(strcmp(com, list[1])==0){
      scanf("%d",&x);
      p=head; q = head->next;
      while(q!=tail && q->n != x){
	p = q; q = q->next;
      }
      if(q!=tail){
	p->next = q->next;
	q->next->prev = p;
      }
    }
    else if(strcmp(com, list[2])==0){
      //printf("check 2\n");
      //if(head == NULL) continue;
      head->next = head->next->next;
      head->next->prev = head;
    }
    else if(strcmp(com, list[3])==0){
      //printf("check 3\n");
      tail->prev = tail->prev->prev;
      tail->prev->next = tail;
    }
    //printf("check\n");
    //p=tail; q = tail->prev;
    //while(q!=head){
    //printf("%d->",q->n);
    //p=q; q=q->prev;
    //}
    //printf(".\n");
  }
  
  p=head; q=head->next;
  while(q!=tail){
    printf("%d",q->n);
    p=q;q=q->next;
    if(q==tail) printf("\n");
    else printf(" ");
  } 

  return 0;
}

