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

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

Node *nil;

void make_node(void);
void insert(int);
void deleteFirst(void);
void deleteLast(void);
Node * Search(int);
void deleteNode(Node *);
void deleteKey(int);
void Print(void);

int main()
{
  int i, n, key;
  char command[15];
  
  scanf("%d", &n);

  make_node();

  for( i = 0 ; i < n ; i++ ){
    scanf("%s", command);
    if( command[0] == 'i' ){
      scanf("%d", &key);
      insert(key);    
    } 
    else if( command[0] == 'd' ){
      if( strlen(command) > 6 ){
	if( command[6] == 'F' ) deleteFirst();
	else if( command[6] == 'L' ) deleteLast();
      }
      else {
	scanf("%d", &key);
	deleteKey(key);
      }
    }
  }

  Print();		      

  return 0;
}

void make_node()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
  
void insert(int key)
{
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

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

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

void deleteKey(int key)
{
  deleteNode(Search(key));
}

void deleteNode(Node *z)
{
  if( z == nil ) return;
  z->prev->next = z->next;
  z->next->prev = z->prev;
  free(z);
}

Node *Search(int key)
{
  Node *v = nil->next;
  while( v != nil && v->key != key ) v = v->next;
  return v;
}

void Print(){
  Node *v = nil->next;
  int cnt=0;
  
  while( 1 ){
    if( v == nil ) break;
    if( cnt++ > 0 ) printf(" ");
    printf("%d", v->key);
    v = v->next;
  }
  printf("\n");
}