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

typedef struct Node *NodePointer;

struct Node{
  int key;
  NodePointer prev,next;
};

void init();
void insert(int);
NodePointer listSearch(int);
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
void deletekey(int);

NodePointer nil;

int main(){
  int i;
  int num;
  char rule[N];
  int key;
  NodePointer n;
  char str1[]="insert";
  char str2[]="delete";
  char str3[]="deleteFirst";
  char str4[]="deleteLast";

  init();

  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf("%s",rule);
    if(strcmp(str3,rule)!=0||strcmp(str4,rule)!=0){
      scanf("%d",&key);
    }
    if(strcmp(str1,rule)==0){
      insert(key);
    }else if(strcmp(str2,rule)==0){
      deletekey(key);
    }else if(strcmp(str3,rule)==0){
      deleteFirst();
    }else if(strcmp(str4,rule)==0){
      deleteLast();
    }
  }

  for(n=nil->next;n!=nil;n=n->next){
    printf("%d",n->key);
    printf(" ");
  }
  printf("\n");

  return 0;
}

void init(){
  nil=malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void insert(int key){
  NodePointer x=malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

NodePointer listSearch(int key){
  NodePointer cur;

  cur=nil->next;

  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void deleteNode(NodePointer del){
  if(del==nil) return;
  del->prev->next=del->next;
  del->next->prev=del->prev;
  free(del);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deletekey(int key){
  deleteNode(listSearch(key));
}