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

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

struct node *NIL;

void init(void){
  NIL = (struct node *)malloc(sizeof(struct node));
  NIL->next = NIL;
  NIL->prev = NIL;
}

void insert(int key){
  struct node *x;

  x = (struct node*)malloc(sizeof(struct node));
  x->key = key;
  x->next = NIL->next;
  NIL->next->prev = x;
  NIL->next = x;
  x->prev = NIL;
}

struct node* listSearch(int key){
  struct node *goal = NIL->next;
  while(goal != NIL && goal->key != key){
    goal = goal->next;
  }
  return goal;
}

void delete(struct node *y){
  if (y == NIL) return;
  y->prev->next = y->next;
  y->next->prev = y->prev;
  free(y);
}

void deleteF(void){
  delete(NIL->next);
}

void deleteL(void){
  delete(NIL->prev);
}

void deleteKey(int key){
  delete(listSearch(key));
}

void print(void){
  struct node *z = NIL->next;
  int flag = 1;

  while(1){
    if (z == NIL) break;
    if (flag == 0) printf(" ");
    printf("%d",z->key);
    z = z->next;
    flag = 0;
  }
  printf("\n");
}

int main(){
  int i;
  int n,key;
  char word[12];

  scanf("%d",&n);

  init();

  for(i=0; i<n; i++){
    scanf("%s",&word);
    if (strcmp(word,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(word,"delete") == 0){
      scanf("%d",&key);
      deleteKey(key);
    }
    else if(strcmp(word,"deleteFirst") == 0){
      deleteF();
    }
    else if(strcmp(word,"deleteLast") == 0){
      deleteL();
    }
  }

  print();

  return 0;
}
