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

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


node *head;

void init(){
head=(node *)malloc(sizeof(node));
head->prev=head;
head->next=head;
}

void insert(int y){
    node *x;
    x=(node *)malloc(sizeof(node));
    x->key=y;
    
    x->next=head->next;
    head->next->prev=x;
    head->next=x;
    x->prev=head;
}


node* listsearch(int num){
    node *cur = head->next;
while(cur!=head&&cur->key!=num){
    cur=cur->next;
    }   
return cur;
}


void delete(node *z){
    if(z==head)return;
    z->prev->next=z->next;
    z->next->prev=z->prev;
    free(z);
}

void deleteFirst(){
  delete(head->next);  
}

void deleteLast(){
    delete(head->prev);
}

void deletekey(int num){
   node *a;
   a=listsearch(num);
    delete(a);
}


int main(){
  int num,n,i,j=1;
  char sel[20];
  node *sel2;
  scanf("%d",&n);
  init();
  for (i=0;i<n;i++){
    scanf("%s",sel);

    if (sel[0]=='i') {
        scanf("%d",&num);
        insert(num); 
    }
    else if(sel[0]=='d') {
      if(strlen(sel)>6){
	    if (sel[6]=='F') deleteFirst();
	    else if(sel[6]=='L') deleteLast();
      }
      else {
        scanf("%d",&num);
        deletekey(num);
      } 
    }
  }
  sel2=head->next;
  while(1){
    if (sel2==head) break;
    if (j==0)printf(" ");
    printf("%d",sel2->key);
    sel2=sel2->next;
    j= 0;
  }
  printf("\n");

  return 0;
}
