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

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

typedef struct node *NodePointer;


NodePointer make1node(NodePointer,int);
void showlist();
NodePointer insert(int);
NodePointer delete(int);
void deletefirst();
NodePointer deletelast();

NodePointer head;

int main(){
  int i, cou, num;
  char str[10];
  

  head = make1node(NULL, 0);
  scanf("%d", &cou);

  
  for (i = 0; i < cou; i ++){
    scanf("%s", str);
    
    if(strcmp(str, "insert") == 0){
      scanf("%d", &num);
      insert(num);
    }
    if(strcmp(str, "delete") == 0){
      scanf("%d", &num);
      delete(num);
    }
    if(strcmp(str, "deleteFirst") == 0){
      deletefirst();
    }
    if(strcmp(str, "deleteLast") == 0){
      deletelast();
    }
  }
      showlist();
  return 0;
}

NodePointer make1node(NodePointer p, int num){
  NodePointer n;
  
  n = (NodePointer)malloc(sizeof(struct node));
  n->next = p;
  n->num = num;

  return n;
}

void showlist(){
  NodePointer p;
  
  for(p = head->next; p != NULL; p = p->next){
    printf("%d ",p->num);
  }
  printf("\n");
}

NodePointer insert(int num){
  NodePointer new;
  new = make1node(head->next, num);
  head->next = new;

  return new;
}

NodePointer delete(int num){
  NodePointer n, del;

  for (n = head; n->next != NULL; n = n->next) {
    if (n->next->num == num){
      del = n->next;
      n->next = del->next;
      free(del);
      return n;
    }
  }
  return NULL;
}

void deletefirst(){
  NodePointer n, del;

  n = head->next;
  free(head);
  head = n;
}

NodePointer deletelast(int num){
  NodePointer n, del;
  
  for (n = head; n->next->next != NULL; n = n->next) {
  }
  del = n->next;
  n->next = NULL;
  free(del);
  return n;
  

}

