#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define M 2000000

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

typedef struct node * NodePointer;

NodePointer nil;
NodePointer L;
char order[M][15];

NodePointer search(int);
void insert(NodePointer);
void delete(NodePointer);
void deleteFirst(NodePointer);
void deleteLast(NodePointer);

int main(){
   
  int n,i;
  NodePointer m;
  

  nil=(NodePointer)malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s %d",order[i],&L->key);

    if(order[i][0]=='i') insert(L);
    else if(order[i][0]=='d'&& order[i][6]=='F') deleteFirst(L);
    else if(order[i][0]=='d'&& order[i][6]=='L') deleteLast(L);
    else delete(L); 
  }

  for(m=nil->next;m!=NULL;m=m->next){
    if(m->next==NULL)printf("%d",m->key);
    else printf("%d \n",m->key);
  }
   
  return 0;
}
   
NodePointer search(int keydata){
  NodePointer n;
  
  for(n=nil;n->next!=NULL;n=n->next){
    if(n->next->key == keydata) return n;
  }
     return NULL;
}

void insert(NodePointer x){

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


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

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

void deleteLast(NodePointer x){
  NodePointer n,delnode;
  for(n=nil;n->next!=NULL;n=n->next){}
     delnode=n;
     n->prev->next=NULL;
}