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

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

void insert(int);
void deleteKey(int);
void delete(node *);
node *searchKey(int);

node *nil;

int main(){
  int n, i, x;
  char scanStr[11];
  int scanInt;
  node *iP;

  nil = (node*)malloc(sizeof(node));
  nil->next = nil->prev = nil;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", scanStr);
    if(strcmp(scanStr,"insert")==0){
      scanf("%d", &x);
      insert(x);
    }
    else if(strcmp(scanStr,"delete")==0){
      scanf("%d", &x);
      deleteKey(x);
    }
    else if(strcmp(scanStr,"deleteFirst")==0) delete(nil->next);
    else if(strcmp(scanStr,"deleteLast")==0) delete(nil->prev);
  }

  //print
  for(iP=nil; iP->next->next != nil; iP=iP->next){
    printf("%d ", iP->next->key);
  }
  printf("%d\n", iP->next->key);

  return 0;
}

void insert(int key){
  //Key??????????????????????????????
  node *newNode;
  //printf("[insert]\n");
  newNode = (node*)malloc(sizeof(node));
  newNode->key = key;

  newNode->next = nil->next;
  newNode->prev = nil;
  nil->next->prev = newNode;
  nil->next = newNode;
}

void deleteKey(int key){
  //printf("[deleteKey]\n");
  delete(searchKey(key));
}

void delete(node *nodeP){
  //printf("[delete]\n");
  nodeP->prev->next = nodeP->next;
  nodeP->next->prev = nodeP->prev;
  free(nodeP);
}

node *searchKey(int key){
  //printf("[searchKey]\n");
  node *iP;

  for(iP=nil->next; iP != nil; iP=iP->next){
    if(iP->key == key) return iP;
  }
}