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

typedef struct Node{
  int key;
  struct Node *next;
  struct Node *prev;
}Node;

void insert(int);
void delete(Node *);
Node *search(int);

Node *nil;

void insert(int key){
    Node *a;

    a = (Node *)malloc(sizeof(Node));
    a->key = key;
    a->next = nil->next;
    a->prev = nil;
    nil->next = a;
    a->next->prev = a;
}

void delete(Node *d){
    if (d == NULL){
        return;
    }
    d->prev->next = d->next;
    d->next->prev = d->prev;
    free(d);
}

Node *search(int key){
    Node *search;
    for(search=nil->next ; search!=nil ; search=search->next){
        if(search->key == key){
          return search;
        }
    }
    return NULL;
}

int main(){
  int i, n, rekey;
  char tstr[20];
  Node *p;

  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil->prev = nil;

  scanf("%d", &n);

  //入力
  for(i=0 ; i<n ; i++){
    scanf("%s", tstr);

    //挿入
    if(strcmp(tstr, "insert") == 0){
        scanf("%d", &rekey);
        insert(rekey);
    }
    //削除
    else if(strcmp(tstr, "delete") == 0){
      scanf("%d", &rekey);
      delete(search(rekey));
    }
    //先頭を削除
    else if(strcmp(tstr, "deleteFirst") == 0){
      delete(nil -> next);
    }
    //末尾を削除
    else if(strcmp(tstr, "deleteLast") == 0){
      delete(nil -> prev);
    }
  }

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

  return 0;
}

