#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct List_tag{
  int n;
  struct List_tag* next;
  struct List_tag* prev;
}List;

List* head;

void insert(int x){
List *l;

 l = malloc(sizeof(List));
 l->n = x;
 if(head != NULL){
 l->next = head;
 l->next->prev = l;
 }
 head = l;


}

void delete(int x){
List *se;
se = head;
  while(se->n != x){

    if(se->next != NULL){
      se = se->next;
    }
    else{
     return;
    }

  }
   if(se->prev != NULL){
  se->prev->next = se->next;
 }

  if(se->next != NULL){
  se->next->prev = se->prev;
  }
  if(se->prev == NULL && se->next != NULL){
   head = se->next;
  }
  if(se->prev == NULL && se->next == NULL)
   head = NULL;

}

void deleteFirst(){
if(head->next != NULL){
  head = head->next;
  head->prev = NULL;
 }
 else{
  head = NULL;
 }


}

void deleteLast(){
List *se;
se = head;
 if(head == NULL)
   return;

 while(se->next != NULL){

  se = se->next;

 }
 if(se == head)
  head = NULL;

 se->prev->next = NULL;

}

void printElement(){
List* l;
l = head;
  if(head == NULL)
   return;

  if(head->n == -1){

   return;
  }
  while(l != NULL){
    if(l->n != -1)
    printf("%d", l->n);

     l = l->next;
    if(l != NULL)
     printf(" ");

  }

 printf("\n");

}



int main(){
char command[20];
int i;
int n;
int p;


scanf("%d", &n);

 for(i = 0; i <= n - 1; i++){
    scanf("%s", command);

    if(strcmp(command, "insert") == 0){
     scanf("%d", &p);
     insert(p);
    }
    else if(strcmp(command, "delete") == 0){
     scanf("%d", &p);
     delete(p);
    }
    else if(strcmp(command, "deleteFirst") == 0){
     deleteFirst();

   }
   else {

    deleteLast();
   }

 }

 printElement();

return 0;
}