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

typedef struct Node{
  int data;
  struct Node *right, *left;
}node;

node *start;

node *list_init(void);
int insert_list(node *p, int x);
void delete_node(node *p);
node *search_x(int x);

int main(void){
  int i, n, x;
  char op[12];
  node *p;

  start = list_init();
  if(start == NULL){
    printf("?????¢????¢??????¨??????\n");
    exit(1);
  }
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", op);
    if(strcmp(op, "insert") == 0){
      scanf("%d", &x);
      if(insert_list(start->right, x) == 0){
	printf("?????¢????¢??????¨??????\n");
	exit(1);
      }
    }else if(strcmp(op, "delete") == 0){
      scanf("%d", &x);
      p = search_x(x);
      if(p != NULL){
	delete_node(p);
      }
    }else if(strcmp(op, "deleteFirst") == 0){
      delete_node(start->right);
    }else if(strcmp(op, "deleteLast") == 0){
      delete_node(start->left);
    } 
  }

  p = start->right;
  while(p != start){
    printf("%d", p->data);
    if(p->right != start){
      printf(" ");
    }
    p = p->right;
  }
  printf("\n");
  return 0;
}


/* ??£????????????????????? */
node *list_init(void){
  node *p = (node *)malloc(sizeof(node));
  if(p != NULL){
    p->right = p;
    p->left = p;
  }
  return p;
}


/* ??£????????????x???p??????????????\ */
int insert_list(node *p, int x){
  node *q = (node *)malloc(sizeof(node));
  if(q == NULL)  return 0;  /* ?????¢????¢??????±??? */
  q->left = p->left;
  q->data = x;
  q->right = p;
  p->left->right = q;
  p->left = q;
  return 1;  /* ?????? */
}


/* ??£??????????????????p?????? */
void delete_node(node *p){
  p->left->right = p->right;
  p->right->left = p->left;
  free(p);
}


/* ??£??????????????????x?????¢?´¢ */
node *search_x(int x){
  node *p = start->right;

  while(p != start){
    if(p->data == x)  break;
    p = p->right;
  }
  if(p == start){
    return NULL;
  }else{
    return p;
  }
}