#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){

  NodePointer n,dummy;

  dummy->key = -1;

  for(n=nil->next;n != nil;n = n->next){
    if(n->key == key){
      //見つかった
      return n;
    }
  }

  //見つからなかった
    return dummy;
  
}


//番兵を作成
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 deleteFirst(){
  NodePointer t = nil->next;

  nil->next = t->next;
  t->next->prev = nil;
}

//リストの最後を削除
void deleteLast(){

  NodePointer delnode = nil->prev;

  nil->prev = delnode->prev;
  delnode->prev->next = nil;
  free(delnode);
}

//入力されたkeyを削除
void delete(int key){
  NodePointer t;
  NodePointer n = nil->next;

  while(n != nil){
    if(n->key == key)
      break;
    n=n->next;
  }

      t = n->prev;
      t->next = n->next;
      t->next->prev = t;
      free(n);

}

//リストの先頭に挿入する
void insert(int key){
  NodePointer x;
  static int count = 0;
  x = malloc(sizeof(struct node));
  x->key = key;

  if(count == 0){
  x->next = nil;
  nil->next = x;
  x->prev = nil;
  nil->prev = x;
  count++;
  }

  else{
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
    count++;
  }
}


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

    if ( com[0] == 'i' ) {
      scanf("%d",&key);
      insert(key);
    }
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' )
	  deleteFirst();
	
	else if ( com[6] == 'L' )
	  deleteLast();
      }
      else{
	scanf("%d",&key);
	if(listSearch(key)->key != -1)
	  delete(key);
      }
    }
  }
  printList();
  return 0;
}