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

#define TRUE 1;
#define FALSE 0;

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

typedef struct node *Node;

void make1node(int);
int delnode(int);

Node nil;
    
int main(){
  int N,num,i;
  char command[15];
  Node n,del;
  nil=malloc(sizeof(struct node));
  nil->prev=nil->next=nil;
  nil->key=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",command);
    if(strcmp("deleteFirst",command)!=0 && strcmp("deleteLast",command)!=0){
    scanf("%d",&num);
    }
        if(strcmp("insert",command)==0)
      make1node(num);
    else if(strcmp("delete",command)==0)
	delnode(num);
    else if(strcmp("deleteFirst",command)==0){
      del=nil->next;
      del->prev->next=del->next;
      del->next->prev=del->prev;
    }
    else if(strcmp("deleteLast",command)==0){
      del=nil->prev;
      nil->prev=del->prev;
      del->prev->next=nil;
    }
      
	    else exit(1);
  } 
  for(n=nil;n->next!=nil;n=n->next){
     printf("%d",n->next->key);
     if(n->next->next==nil) printf("\n");
     else printf(" ");
  }
  
  return 0;
}
void make1node(int key){
  Node n;
  n=(Node)malloc(sizeof(struct node));
    n->key=key;
    n->next=nil->next;
    n->next->prev=n;
    nil->next=n;
  n->prev=nil;
  
}
int delnode(int key){
  Node n,delnode;
  for(n=nil;n->next!=nil;n=n->next){
    if(n->next->key==key){
      delnode=n->next;
      delnode->prev->next=delnode->next;
      n->next->prev=delnode->prev;
      free(delnode);
      return TRUE;
    }
  }
  return FALSE; 
}

      
     

