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

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

struct node *nil;

void insert(int);
void delete(struct node*);
struct node* search(int);
void listPrint(void);

int main() {
  int n, i, x;
  char str[15];

  scanf("%d", &n);
  nil = (struct node*)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;

  for(i = 0; i < n; i++) {
    scanf("%s", str);
    if(str[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    }
    else if(str[0] == 'd' ) {
      if(str[6] == '\0') {
        scanf("%d", &x);
        delete(search(x));
      }
      else if(str[6] == 'F') {
        delete(nil->next);
      }
      else {
        delete(nil->prev);
      }
    }
  }
  listPrint();
  return 0;
}

void insert(int key) {
  struct node* newnode = (struct node*)malloc(sizeof(struct node));
  newnode->key = key;
  newnode->next = nil->next;
  nil->next->prev = newnode;
  nil->next = newnode;
  newnode->prev = nil;
}

void delete(struct node* delnode) {
  delnode->prev->next = delnode->next;
  delnode->next->prev = delnode->prev;
  free(delnode);
}

struct node* search(int key) {
  struct node* searchnode = nil->next;
  while (searchnode != nil && searchnode->key != key) {
    searchnode = searchnode->next;
  }
  return searchnode;
}

void listPrint() {
  int i = 0;
  struct node* n = nil->next;
  while (1) {
    if(n == nil) break;
    if(i > 0) printf(" ");
    i++;
    printf("%d", n->key);
    n = n->next;
  }
  printf("\n");
}