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

typedef struct element{
  long key;
  struct element *next;
  struct element *before;
}Element;

Element *insert(Element *begin, long key) {
  Element *p;
  p = (Element*)malloc(sizeof(Element));
  p->key = key;
  p->next = begin;
  p->before = NULL;
  if(begin != NULL) begin->before = p;
  return p;
}

Element *delete(Element *begin, long key) {
  Element *p = begin,*temp;
  while(p->key != key) p = p->next;
  if(p->before != NULL) p->before->next = p->next;
  if(p->next != NULL) p->next->before = p->before;
  temp = begin;
  if(p == begin) temp = begin->next;
  free(p);

  return temp;
}

Element *deleteFirst(Element *begin) {
  Element *p = begin->next;
  if(p != NULL) p->before = NULL;
  free(begin);

  return p;
}

Element *deleteLast(Element *begin) {
  Element *p = begin,*temp;
  while(p->next != NULL) p = p->next;
  temp = begin;
  if(p == begin) temp = NULL;
  free(p);

  return temp;
}

int main() {
  long i,n;
  scanf("%ld", &n);
  char command[12];
  long key;
  Element *begin;
  for(i = 0; i < n; i++) {
    scanf(" %s %ld", command, &key);
    if(strcmp(command,"insert") == 0) begin = insert(begin, key);
    if(strcmp(command,"delete") == 0) begin = delete(begin, key);
    if(strcmp(command,"deleteFirst") == 0) begin = deleteFirst(begin);
    if(strcmp(command,"deleteLast") == 0) begin = deleteLast(begin);
  }

  Element *p = begin;
  while(p->next != NULL) {
    printf("%ld ", p->key);
    p = p->next;
  }
  printf("%ld\n", p->key);

  return 0;
}