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

struct Point{
  int next;
  struct Point *front,*back;
};

struct Point *nil;

struct Point* Search(int);
void PrintList();
void input();
void deletePoint (struct Point *st);
void delete (int next);
void insert (int next);
void First();
void Last();

int main(){
  int i,n,key;
  char hi[20];

  scanf("%d",&n);
  input();

  for(i=0;i<n;i++){
    scanf("%s",hi);
    if(hi[0]=='i'){
      scanf("%d", &key);
      insert(key);
    }
    if(hi[0]=='d'){
      if(6<strlen(hi)){
	if(hi[6]=='F')
	  First();
	else if(hi[6]=='L')
	  Last();
      }else{
	scanf("%d", &key);
	delete(key);
      }
    }
  }

 
 
  PrintList();

  return 0;
}
  

struct Point* Search(int next){
  struct Point *a=nil->back;
  while(a!=nil && a->next != next){
    a=a->back;
  }
  return a;
}

void PrintList()
{
  int cou=0;
  struct Point *a=nil->back;

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

void input()
{
  nil=(struct Point *)malloc(sizeof(struct Point));
  nil->back=nil;
  nil->front=nil;
}

void deletePoint (struct Point *st){/*削除*/
  if(st==nil)
    return;
  st->front->back= st->back;
  st->back->front= st->front;
  free(st);
}

void delete (int next){
  deletePoint(Search(next));
}

void insert (int next){
  struct Point *b=(struct Point *)malloc(sizeof(struct Point));
  b->next=next;
  
  b->back=nil->back;
  nil->back->front=b;
  nil->back=b;
  b->front=nil;
}

void First(){/*リストの先頭の要素を削除する*/
  deletePoint (nil->back);
}

void Last(){/*リストの末尾の要素を削除する*/
  deletePoint(nil->front);
}
  

