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

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

typedef struct node *NodePointer;
NodePointer nil;

NodePointer search(int);
void insert(int);
void deleteN(NodePointer);
void delete(int);
void deleteF(void);
void deleteL(void);

int main(){
  int i;
  int  n,k,flag=1;
  char input[15];
  NodePointer x;

  nil=malloc(sizeof(struct node));
  nil->prev=nil;
  nil->next=nil;

  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
      scanf("%s",input);
      if(strcmp(input,"insert")==0)
	{
	  scanf("%d",&k);
	  insert(k);
	}
      else if(strcmp(input,"delete")==0)
	{
	  scanf("%d",&k);
	  delete(k);	  
	}
      else if(strcmp(input,"deleteFirst")==0)
	{
	  deleteF(); 	  
	}
      else if(strcmp(input,"deleteLast")==0)
	{
	  deleteL(); 	  
	}
    }
  
  x=nil->next;
  
  while(1){
    if(x==nil) break;
    if(flag==0) printf(" ");
    printf("%d",x->key);
    x=x->next;
    flag=0;
  }
  printf("\n");
  
  return 0;
}

NodePointer search(int k){
  NodePointer x;

  x=nil->next;
  while(x!=nil && x->key!=k){
    x=x->next;
  }

  return x;
}

void insert(int k){
  NodePointer x;

  x=malloc(sizeof(struct node));
  x->key=k;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

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

void delete(int k){
  NodePointer x;

  x=search(k);
  if(x==nil) return;
  deleteN(x);
}

void deleteF(){
  NodePointer x;

  x=nil->next;
  deleteN(x);
}

void deleteL(){
  NodePointer x;

  x=nil->prev;
  deleteN(x);
}

