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

struct node{
  int key;
  struct node *next,*previous;
};
typedef struct node Node;
void deleteNode(Node *);
Node *listSearch(int);
Node *nil;

void insert(int key){
  Node *node=(Node *)malloc(sizeof(Node));
  node->key=key;
  node->next=nil->next;
  nil->next->previous=node;
  nil->next=node;
  node->previous=nil;
}
void deleteKey(int key){
  deleteNode(listSearch(key));
}
void deleteLast(){
  deleteNode(nil->previous);
}
void deleteFirst(){
  deleteNode(nil->next);
}
void deleteNode(Node *t){
  if(t==nil)return;
  t->previous->next=t->next;
  t->next->previous=t->previous;
  free(t);
}
Node *listSearch(int key){
  Node *node=nil->next;
  while(node!=nil && node->key!=key){
    node=node->next;
  }
  return node;
}
void echoooo(void){
  Node *now=nil->next;
  while(1){
    if(now==nil)break;
    printf("%d",now->key);
    if(now->next!=nil)printf(" ");
    now=now->next;
  }
  printf("\n");
}
int main(void){
  //nd is node delete count
  int key,n,i;
  char command[12];
  //initialization
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->previous=nil;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(command[0]=='d'){
      if(strlen(command)>6){
        if(command[6]=='F')deleteFirst();
        else if(command[6]=='L')deleteLast();
      }else {
        scanf("%d",&key);
        deleteKey(key);
      }
    }
  }

  echoooo();
  return 0;
}
