/*Doubly Linked List*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{ 
  int key; 
  struct node *next;
  struct node *prev; 
}; 
typedef struct node * NodePointer;
NodePointer nil; 

void insert(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
void init(){
  nil->key=0;
  nil->next=NULL;
  nil->prev=NULL;
}

int main(){  
  NodePointer p;
  int i, n, key;
  char com[12];
  scanf("%d", &n); 
  init(); 
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key); 
    if ( com[0] == 'i' ) { 
      insert(key); 
    } else if ( com[0] == 'd' ) { 
      if (strlen(com) > 6){ 
	if ( com[6] == 'F' ) {
	  deleteFirst(); 
	} else if ( com[6] == 'L' ) { 
	  deleteLast(); 
	} 
      } else { 
	delete(key); 
      } 
    } 
  } 
  for(p=nil->next;p!=nil;p=p->next){
    if(p!=nil->prev)printf("%d ",p->key);
    else printf("%d\n",p->key);
  }
  return 0; 
} 

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

void delete(int key){
  NodePointer x;
  x->key=key;
  x->prev->next=x->next;
  x->next->prev=x->prev;
  free(x);
}

void deleteFirst(){
  nil->next->next->prev=nil;
  nil->next=nil->next->next;
  free(nil->next);
}

void deleteLast(){
  nil->prev=nil->prev->prev;
  nil->prev->prev->next=nil;
  free(nil->prev);
}