#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 delete(NodePointer);
void insert(int);
void deleteFirst(void);
void deleteLast(void);
void init(void);
void listPrint(void);
NodePointer search(int);

int main()
{
  int n,i,k;
  char com[20];

  scanf("%d",&n);
  init();
  
  for(i = 0; i < n; i++){
    scanf("%s",com);
    if(strcmp(com, "delete") == 0){
      scanf("%d",&k);
      delete(search(k));
    }
    else if(strcmp(com, "insert") == 0){
      scanf("%d",&k);
      insert(k);
    }
    else if(strcmp(com, "deleteFirst") == 0)
      deleteFirst();
    else if(strcmp(com, "deleteLast") == 0)
      deleteLast();
  }
  listPrint();

  return 0;
}

void insert(int key)
{
  NodePointer x;

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

NodePointer search(int key)
{
  NodePointer i;

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

void delete(NodePointer x)
{ 
  if(x == nil)return;
  x->prev->next = x->next;
  x->next->prev = x->prev;
  free(x);
}

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

void deleteLast(void)
{
  delete(nil->prev);
}

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

void listPrint(void)
{
  NodePointer t = nil->next;
  int a = 0;

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

