#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 256

typedef struct DoublyLinkedList{
  struct DoublyLinkedList *prev;
  struct DoublyLinkedList *next;
  int value;
} DoublyLinkedList;

void insert(DoublyLinkedList *dll, int value){
  DoublyLinkedList *newNode = (DoublyLinkedList *) malloc(sizeof(DoublyLinkedList));
  newNode->prev = dll;
  newNode->next = dll->next;
  newNode->value = value;
  dll->next->prev = newNode;
  dll->next = newNode;
}

void delete(DoublyLinkedList *dll, int value){
  int nextValue = dll->next->value;
  if(nextValue == value){
    free(dll->next);
    dll->next = dll->next->next;
    dll->next->prev = dll;
  }else if(nextValue != -1){
    delete(dll->next, value);
  }
}

void deleteFirst(DoublyLinkedList *dll){
  if(dll->next->value != -1){
    free(dll->next);
    dll->next = dll->next->next;
    dll->next->prev = dll;
  }
}

void deleteLast(DoublyLinkedList *dll){
  if(dll->prev->value != -1){
    free(dll->prev);
    dll->prev = dll->prev->prev;
    dll->prev->next = dll;
  }
}

void printAll(DoublyLinkedList *dll){
  if(dll->next->value != -1){
    if(dll->value != -1){
      printf("%d ", dll->value);
    }
    printAll(dll->next);
  }else{
    printf("%d\n", dll->value);
  }
}

int main(){
  int i, n, value = 0;
  char line[MAX], buf[MAX];
  char *cmd, *tmp;
  DoublyLinkedList dll;

  dll.prev = &dll;
  dll.next = &dll;
  dll.value = -1;

  scanf("%d", &n);
  fgets(buf, sizeof(buf), stdin);
  for(i = 0; i < n; i++){
    fgets(line, sizeof(line), stdin);
    strtok(line, "\n\0");

    cmd = strtok(line, " ");
    tmp = strtok(NULL, " ");
    if(tmp != NULL){
      value = atoi(tmp);
    }
    if(!strcmp(cmd, "insert")){
      insert(&dll, value);
    }else if(!strcmp(cmd, "delete")){
      delete(&dll, value);
    }else if(!strcmp(cmd, "deleteFirst")){
      deleteFirst(&dll);
    }else if(!strcmp(cmd, "deleteLast")){
      deleteLast(&dll);
    }
  }
  printAll(&dll);

  return 0;
}