#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node *link;

struct node{
  int item;
  link next, prev;
};

int main(void){
  int n, i, j, getitem, size = 0;
  char s[16];
  link head, end;
  head = malloc(sizeof(*head));
  head->item = -1;
  head->next = NULL;
  head->prev = NULL;
  end = head;
  
  scanf("%d", &n); //input number
  
  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(!strcmp(s, "insert")){ //insert
      scanf("%d", &getitem);
      link x;
      x = malloc(sizeof(*x));
      x->item = getitem;
      x->next = head;
      x->prev = NULL;
      head->prev = x;
      head = x;
      size++;
    }else if(!strcmp(s, "delete")){ //delete
      scanf("%d", &getitem);
      link x;
      x = malloc(sizeof(*x));
      x = head;
      if(head->item == getitem){ //head is delete point
	head = head->next;
	head->prev = NULL;
	size--;
	continue;
      }
      while(x->next->item != -1){ //look for delete point
	if(x->next->item == getitem){
	  x->next = x->next->next;
	  x->next->prev = x;
	  size--;
	  break;
	}else{
	  x = x->next;
	}
      }
    }else if(!strcmp(s, "deleteFirst")){ //deleteFirst
      if(size == 0){
	continue;
      }
      head = head->next;
      head->prev = NULL;
      size--;
    }else if(!strcmp(s, "deleteLast")){ //deleteLast
      if(size == 0){ //no element 
	continue;
      }else if(size == 1){ //only one element(same as deleteFirst)
	head = head->next;
	head->prev = NULL;
	size--;
	continue;
      }
      end->prev->prev->next = end;
      size--;
    }
  }


  //output
  link x;
  x = malloc(sizeof(*x));
  x = head;
  for(i = 0; i < size-1; i++){
    printf("%d ", x->item);
    x = x->next;
  }
  printf("%d\n", x->item);
  return 0;
}