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

struct Node{
  int data;
  struct Node *next, *prev;
};
/* typedef struct */
 
struct Node *node;


void init(void);
void Insert(int);
struct Node* listSearch(int);
void delete(struct Node *);
void deleteFirst(void);
void deleteLast(void);
void listprint(void);
void deletekey(int);

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


struct Node* listSearch(int data){
  struct Node *a;
  a = nil->next;
  while(a!=nil && a->data!=data){
    a = a->next;
  }
  return a;
}



void Insert(int data){
  struct Node *x = (struct Node *)malloc(sizeof(struct Node));
  x->data = data;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}





void delete(struct Node *a){
  if(a == nil)return;
  a->prev->next = a->next;
  a->next->prev = a->prev;
  free(a);
}

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

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

void deletekey(int data){
  delete(listSearch(data));
}

void listprint(){
  struct Node *n;
  printf("%d",nil->next->data);
  for(n=nil->next->next;n!=nil;n=n->next){
    printf(" %d",n->data);
  }
  printf("\n");
}



int main(){
  int i,j,a,b;
  char c[20];
  struct Node *d;
  char e[] = "insert";
  char f[] = "delete";
  char g[] = "deleteFirst";
  char h[] = "deleteLast";
  
  scanf("%d",&a);
  init();
  for(i=0;i<a;i++){
    scanf("%s%d",c,&b);
    if(strcmp(c,e)==0) Insert(b);
    else if(strcmp(c,f)==0) deletekey(b);
    else if(strcmp(c,g)==0) deleteFirst();
    else if(strcmp(c,h)==0) deleteLast();
  }
  
  listprint();
  return 0;
}