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

typedef struct node{
  int num;
  struct node *next;
  struct node *back;
}Node;

Node *nil;

void insert(int x){
  Node *newNode;
  newNode = (Node *)malloc(sizeof(Node));
  newNode->num = x;

  newNode->next = nil->next;
  newNode->back = nil;
  newNode->next->back = newNode;
  nil->next = newNode;
  if(nil->back == nil) nil->back = newNode;
}

void delete(int x){
  Node *del;
  del = nil;

  while(1){
    if(del->next->num == x) break;
    else del = del->next;

    if(del == nil) return;
  }

  del->next = del->next->next;
  del->next->back = del;
}

void deleteFirst(){
  nil->next = nil->next->next;
  nil->next->back = nil;
}

void deleteLast(){
  Node *del;
  del = nil->back;
  del->back->next = nil;
  nil->back = del->back;
}

int main(){
  int i,j,exist=0;

  char c[7];
  int x;

  nil = (Node *)malloc(sizeof(Node));

  nil->num = -1;
  nil->next = nil;
  nil->back = nil;

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


  for(i=0;i<n;i++){
    //printf("%d\n",i);
    for(j=0;j<8;j++){
      if(j==0){
         scanf("%c",&c[j]);
         continue;
      }
      scanf("%c",&c[j-1]);
      // if(c[j-1]=='\0'){
      // printf("sjsjs\n");
      // c[j-1]=' ';
      // }
    }
    /*for(j=0;j<7;j++){
      printf("%c",c[j]);
    }*/
    if(c[0]=='i'){
      scanf("%d",&x);
    //  printf("%d\n",x);

      insert(x);
    }else if(c[0]=='d'){
      if(c[6]==' '){
        scanf("%d",&x);
      //  printf("%d\n",x);

        delete(x);
      }else if(c[6]=='F'){
      //  printf("first\n");
        for(j=0;j<4;j++){
          scanf("%c",&c[0]);
        }

        deleteFirst();
      }else if(c[6]=='L'){
      //  printf("Last\n");
        for(j=0;j<3;j++){
          scanf("%c",&c[0]);
        }

        deleteLast();
      }
    }
      //printf("%d\n",nil->back->num);
  }

  Node *mark;
  mark = nil;

  //printf("%d\n",mark->next->num);

  while(1){
    if(mark->next != nil){
      if(exist) printf(" ");
      printf("%d",mark->next->num);
      mark = mark->next;
      exist = 1;
    }
    else break;
  }
  printf("\n");

  return 0;
}

