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

typedef struct node Node;

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

Node *data;

Node* ListSearch(int);
void insert(int);
void mk(void);
void ListPrint(void);
void DeleteNode(Node*);
void DeleteKey(int);
void DeleteFirst(void);
void DeleteLast(void);

int main()
{
  int i,key,n;
  int np=0,nd=0,size=0;
  char array[20];
  
  scanf("%d",&n);
  mk();

  for(i=0;i<n;i++){
    scanf("%s%d",array,&key);
    if(array[0]=='i'){
      insert(key);
    }
    else if(array[0]=='d'){
      if(strlen(array)>6){
	if(array[6]=='F') DeleteFirst(); //delete"F"irst
	if(array[6]=='L') DeleteLast(); //delete"L"ast
      }
      else{
	DeleteKey(key);
      }

    }
  }
  
  ListPrint();
      
  return 0;
}

Node* ListSearch(int key)
{
  Node *p;

  p = data->next;
  while(p!=data && p->key!=key)
    p = p->next;
  
  return p;
}

void insert(int key)
{
  Node *p = (Node *)malloc(sizeof(Node));
  
  p->next = data->next;
  p->key = key;
  data->next->prev = p;
  data->next = p;
  p->prev = data; //pをリストに繋げていく
}

void mk()
{
  data = (Node *)malloc(sizeof(Node));
  data->next = data;
  data->prev = data;
}

void ListPrint()
{
  int num=0;
  Node *p;

  p = data->next;
  while(1){
    if(p==data) break;
    if(num>0) printf(" ");
    printf("%d",p->key);
    p = p->next;
    num++;
  }
  printf("\n");
}

void DeleteNode(Node *p)
{
  if(p==data) return;
  p->prev->next = p->next;
  p->next->prev = p->prev; //pに繋いでるものをうつす
  free(p);
}

void DeleteKey(int key)
{
  DeleteNode(ListSearch(key));
}

void DeleteFirst()
{
  DeleteNode(data->next);
}

void DeleteLast()
{
  DeleteNode(data->prev);
}
    

