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

struct node{
  int key;
  struct node *next;
  struct node *prev;
};
typedef struct node * NodePointer;
NodePointer nil;

void set(){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void list(){
    NodePointer n = nil->next;
    int i = 1;

    while(1){
      if(n == nil) break;
      if(i == 0) printf(" ");
      printf("%d",n->key);
      n = n->next; i = 0;
    }
    printf("\n");
  }

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

void deleteNode(NodePointer p){
  p->next->prev = p->prev;
  p->prev->next = p->next;
  free(p);
}

void deleteFirst(){
  NodePointer n = nil->next;
  if(n == nil)return;
  deleteNode(n);
}

void deleteLast(){
  NodePointer n = nil->prev;
  if(n == nil) return;
  deleteNode(n);
}

void delete(int key){
  NodePointer n;
  if((n = find(key)) != NULL) deleteNode(n);
}

void insert(int key){
  NodePointer newnode;
    newnode =(NodePointer)malloc(sizeof(struct node));
    newnode->key = key;
    newnode->next = nil->next;
    newnode->prev = nil;
    nil->next->prev = newnode;
    nil->next = newnode;
}

int main(){
  int n,i,key,j=1;
  char str[20];

  set();

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",str);
    if(strcmp("insert",str) == 0){
      scanf("%d",&key);
      insert(key);
    }
    if(strcmp("delete",str) == 0){
      scanf("%d",&key);
      delete(key);
    }
    if(strcmp("deleteFirst",str) == 0)deleteFirst();
    if(strcmp("deleteLast",str) == 0)deleteLast();
  }
  list();
  return 0;
}

