/*双方向連結リスト*/
#include <stdio.h>
#include <stdlib.h>

struct node{
  unsigned long key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

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

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%ld", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->next->prev = t->prev;
  t->prev->next = t->next;
}


void deleteFirst(){
  NodePointer t = nil->next;
  if ( t != nil ){
    deleteNode(t);
  }
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer del = nil->next;
  while(1){
    if (del->key == key){
      deleteNode(del);
      break;
    }
    del = del->next;
  }
}


void insert(int key){
  NodePointer x, s = nil;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->prev = nil;
  nil->next = x;
  while(1){
    if (s->prev == nil){
      x->next = s;
      s->prev = x;
      break;
    }
    s = s->prev;
  }
}

int main(){
  int n, i;
  long key;
  char com[20];
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if (com[0] == 'i'){
      scanf("%ld", &key);
      insert(key);
    }
    else if (com[0] == 'd'){
      if (com[6] == 'F')
	deleteFirst();
      else if(com[6] == 'L')
	deleteLast();
      else{
	scanf("%ld", &key);
	delete(key);
      }
    }
  }

  printList();
  return 0;
}

