#include<stdio.h>


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


int main(){

  Node A[500000];
  Node first;
  Node final;
  Node *box;
  
  first.next = &final;
  final.prev = &first;
  
  int i,n,x,count=0;
  char c[14];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0] == 'i'){
      scanf("%d",&x);
      first.next->prev = &A[count];
      A[count].next = first.next;
      first.next = &A[count];
      A[count].prev = &first;
      A[count].key = x;
      count++;
    }
    else if(c[6] == 'F'){
      first.next->next->prev = &first;
      first.next = first.next->next;
    }
    else if(c[6] == 'L'){
      final.prev->prev->next = &final;
      final.prev = final.prev->prev;
    }
    else{
      scanf("%d",&x);
      box = first.next;
      while(box != &final){
	if(box->key == x){
	  box->prev->next = box->next;
	  box->next->prev = box->prev;
	  break;
	}
	box = box->next;
      }
    }
  }
    box = &first;
    while(box != final.prev->prev){
      printf("%d ",box->next->key);
      box = box->next;
    }
    printf("%d\n",box->next->key);
  
    return 0;
}