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

typedef struct{
  int val, flag;
}P;

void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();

int head, top, j=0;
P Q[1000];

int main(){

  int i, n, b;
  char a[2000][20];

  scanf("%d",&n);

  head=0;

  for(i=0;i<n;i++){
    scanf("%s",a[i]);
    if(strcmp(a[i],"insert")==0){
      scanf("%d",&b);
      insert(b);
    }
    else if(strcmp(a[i],"delete")==0){
      scanf("%d",&b);
      //  printf("\nb %d\n",b);
      delete(b);	
    }
    else if(strcmp(a[i],"deleteLast")==0){
      deleteLast();	
    }
    else{
      deleteFirst();	
    }
  }
  i=j-1;
  while(1){
    if(Q[i].flag!=1){
      printf("%d",Q[i].val);
      break;
    }
    i--;
  }
  i--;
  for(;i>0;i--){
    if(Q[i].flag!=1)printf(" %d",Q[i].val);
  }
  printf("\n");
  return 0;
}
void insert(int b){
  Q[j].val = b;
  Q[j].flag = 0;
  j++;
}
void delete(int b){
  int i;
  for(i=j-1;i>=0;i--){

    if(Q[i].val==b && Q[i].flag!=1){
      Q[i].flag=1;
      break;
    }
  }
}
void deleteFirst(){
  int i;

  for(i=j-1;i>=0;i--){
    if(Q[i].flag!=1){
      Q[i].flag=1;
      break;
    }
  }
}
void deleteLast(){
  int i;
  for(i=0;i<j;i++){
    if(Q[i].flag!=1){  
      Q[i].flag=1;
      break;
    }
  }
}