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

//ノード
struct node{
  unsigned int key;
  struct node *next;//ノードの接続先
  struct node *prev;//ノードの接続元
};


typedef struct node * NodePointer;

//ノード列
NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
}

//nilの初期化
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("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

//void deleteNode(NodePointer t){
/* your code */
//}

void deleteFirst(){
  NodePointer t = nil->next;
  //printf("first in\n");
  if ( t == nil ){
    return;
  }else{
    t->prev->next = t->next;
    t->next->prev = t->prev;
  }
  //printf("first out\n" );
}

void deleteLast(){
  NodePointer t = nil->prev;
  //printf("last in\n" );
  if ( t == nil ){
    return;
  }else{
    t->prev->next = t->next;
    t->next->prev = t->prev;
  }
  //printf("last out\n" );
}

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

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

int main(){
  int key, n, i;
  int size = 0;
  char com[20];//命令 insert or delete
  int np = 0, nd = 0;
  //命令数の入力
  scanf("%d", &n);
  init();
  //命令数分だけ命令を入力する
  for ( i = 0; i < n; i++ ){
    //printf("roop[%d]\n",i );
    scanf("%s %d", com, &key);
    //printf("scan[%d]\n",i );
    if ( com[0] == 'i' ){
      insert(key);
      np++;
      size++;
    }
    else if ( com[0] == 'd' ){
      if (strlen(com) > 6){
        if ( com[6] == 'F' ){
          deleteFirst();
          //printf("back from first\n");
        }else if ( com[6] == 'L' ){
          //printf("delete last now\n" );
          deleteLast();
          //printf("last\n" );
        }
      }else {
        delete(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}

