#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();
void insert(int);
void delete(int);
void deletefirst();
void deletelast();

NodePointer head;

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

  head = make1node(NULL, 0);
  head->next = head;
  head->prev = head;
  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 n;

  n = head->next;
  while(n != head){
    printf("%d ",n->num);
    n = n->next;
  }
  printf("\n");
}

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

void delete(int num){
  NodePointer n;
  /*
  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;
  */

  n = head->next;
  while(n != head && n->num != num){
    n = n->next;
  }
  if(n != head){
    n->prev->next = n->next;
    n->next->prev = n->prev;
    free(n);
  }
}

void deletefirst(){
  NodePointer n;

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

void deletelast(){
  NodePointer n, del;

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

