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


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

typedef struct node *NodePointer;


void insert(int);
void delete(int);
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
NodePointer find(int);
NodePointer make_1node();
void ListPrint();


NodePointer nil; 


int main () {
  char str[15];
  int n = 0, i, x = 0;

  nil = make_1node(); //二分木の場合

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%s",str);
    //scanf("%d",&x);
    //printf("i = %d\n", i);
    //scanf("%s%d", str, &x);
    if(strcmp(str, "insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(str, "delete") == 0) {
      scanf("%d",&x);
      delete(x);
    }
    else if(strcmp(str, "deleteFirst") == 0) deleteFirst();
    else if(strcmp(str, "deleteLast") == 0) deleteLast();

    //ListPrint();
  }

  ListPrint();

  
  return 0;
}

void insert(int key) {
  NodePointer p;

  p = (NodePointer)malloc(sizeof(struct node));
  p->key = key;
  
  p->next = nil->next;
  nil->next->prev = p;
  nil->next = p;
  p->prev = nil;
  
}


NodePointer find(int key) {
  NodePointer n;

  for(n = nil->next ; n != nil ; n = n->next) {
    if(n->key == key) return n;
  }

  return NULL;
}


NodePointer make_1node() {
  NodePointer n;

  if((n = (NodePointer)malloc(sizeof(struct node))) == NULL) {
    exit(8);
  }

  n->next = n;
  n->prev = n;

  return n;
}

void delete(int key) {
  NodePointer n;
  n = find(key);

  if(n != NULL) {
    deleteNode(n);
  }
}

void deleteNode(NodePointer t) {
  //printf("key:%d\n", t->key);
  if(t != nil) {
    t->prev->next = t->next;
    t->next->prev = t->prev;
    
    free(t);
  }
}

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

void deleteLast() {
  //printf("last\n");
  deleteNode(nil->prev);
}


void ListPrint() {
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

