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

struct node{
  int key; 
  struct node *next;
  struct node *prev;
};
struct node* insert(int);
struct node* finditem(int);
struct node* make_1node(int,struct node*,struct node*);
void delete(int);
struct node *head;

int main(){
  int n, i, key=0;
  char com[11];
  struct node *m, *del;
  head = make_1node(key,NULL,NULL);
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s%d",com,&key);
    if(0 == strcmp(com,"insert")){
      insert(key);
    }
    else if(0 == strcmp(com,"delete")){
	delete(key);
    }
    else if(0 == strcmp(com,"deleteFirst")){
      del = head->next;
    head->next = head->next->next;
    free(del);
    }
    else if(0 == strcmp(com,"deleteLast")){
      for(m=head->next; m->next!=NULL; m=m->next);
      m->prev->next = NULL;
      free(m);
    }
  }
  for(m=head->next; m!=NULL; m=m->next){
    printf("%d",m->key);
    if(m->next != NULL)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
  }

struct node* insert(int key)
{
  struct node *n;
  if (finditem(key) == NULL) {
    head->next = make_1node(key, head, head->next);
    return head->next;
  }
  else return NULL;
}

struct node* finditem(int key)
{
  struct node *n;
  for (n = head->next; n != NULL; n = n->next) {
    if (n->key == key) return n;
  }
  return NULL;
}

 struct node* make_1node(int key, struct node *p, struct node *q)
{
  struct node *n;
  n = (struct node*)malloc(sizeof(struct node));
  n->key = key;
  n->next = q;
  n->prev = p;
  return n;
}

 void delete(int key){
   struct node *n;
   n = finditem(key);
   if(n != NULL){
   n->prev->next = n->next;
   if(n->next != NULL)
     n->next->prev = n->prev;
   free(n);
   }
 }