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

struct Node{
  int key;
  struct Node *next;
  struct Node *prev;
};

typedef struct Node * NodePointer;

NodePointer Nil;

NodePointer make1node(int);
NodePointer search(int);
void insert(int);
void delete(int);
void listprint();

int main(){
  int n;
  char **command;
  char str[20];
  int key;
  int i;
  NodePointer head;

  Nil = make1node(-1);
  Nil->next = Nil;
  Nil->prev = Nil;

  head = Nil;

  scanf("%d ",&n);

  command = (char **)malloc(n*sizeof(char *));
  
  for(i=0; i<n; i++){
    fgets(str, 20, stdin);
    command[i] = (char *)malloc((strlen(str)+1)*sizeof(char));
    strcpy(command[i],str);
    command[i][strlen(command[i])-1] = '\0';
  }

  for(i=0; i<n; i++){
    if(!strncmp(command[i],"insert ",7)){
      key = atoi(&command[i][7]);
      insert(key);
    }
    
    else if(!strncmp(command[i],"delete ",7)){
      key = atoi(&command[i][7]);
      delete(key);
    }
    
    else if(!strcmp(command[i],"deleteFirst")){
      delete(Nil->next->key);
    }
    
    else if(!strcmp(command[i],"deleteLast")){
      delete(Nil->prev->key);
    }
  }

  listprint();

  for(i=0; i<n; i++)
    free(command[i]);
  free(command);
  return 0;
}

NodePointer make1node(int key){
  NodePointer n;

  n = (NodePointer)malloc(sizeof(struct Node));

  n->key = key;

  return n;
}

NodePointer search(int key){
  NodePointer x;
  x = Nil->prev;

  while(x!=Nil && x->key!=key)
    x=x->prev;

  return x;
}

void insert(int key){
  NodePointer x;

  x = make1node(key);
  
  x->next = Nil->next;
  Nil->next->prev = x;
  Nil->next = x;
  x->prev = Nil;
}

void delete(int key){
  NodePointer x;

  x = search(key);
  if(x!=Nil){
    x->prev->next = x->next;
    x->next->prev = x->prev;

    free(x);
  }
}

void listprint(){
  NodePointer x;

  for(x = Nil->next; x!=Nil; x=x->next){
    printf("%d",x->key);
    if(x->next!=Nil)
      printf(" ");
  }
  printf("\n");
}

