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

#define BUF_SIZE 30

struct list {
  struct list *prev, *next;
  int number;
};

struct list* create_list() {
  struct list *head = malloc(sizeof(struct list));
  head->prev = head->next = head;
  return head;
}

void print_list(struct list *head) {
  struct list *tmp;
  for(tmp = head->next; tmp != head; tmp = tmp->next) {
    printf("%d%c", tmp->number, tmp->next == head ? '\n' : ' ');
  }
}

struct list* find(struct list *head, int num) {
  struct list *tmp;
  for(tmp = head->next; tmp != head; tmp = tmp->next) {
    if(tmp->number == num) {
      return tmp;
    }
  }
  return NULL;
}

void insert(struct list *head, int num) {
  struct list *elem = malloc(sizeof(struct list));
  elem->next = head->next;
  elem->prev = head;
  elem->number = num;
  head->next->prev = elem;
  head->next = elem;
}

void delete(struct list *head, int num) {
  struct list *elem = find(head, num);
  if(!elem) return;
  elem->prev->next = elem->next;
  elem->next->prev = elem->prev;
  free(elem);
}

void deleteFirst(struct list *head) {
  struct list *elem = head->next;
  if(elem == head) return;
  head->next = elem->next;
  elem->next->prev = head;
  free(elem);
}

void deleteLast(struct list *head) {
  struct list *last = head->prev;
  if(last == head) return;
  last->prev->next = head;
  head->prev = last->prev;
  free(last);
}


int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line,BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);

  struct list *head = create_list();

  int i;
  for(i = 0; i < num; i++) {
    if(!fgets(line,BUF_SIZE, fp)) return 0;
    int n;
    char command[12];
    sscanf(line, "%s %d", command, &n);
    if(!strncmp(command, "insert", 6)) {
      insert(head, n);
    } else if(!strncmp(command, "delete", 6)) {
      if(!strncmp(&command[6], "First", 5)) {
        deleteFirst(head);
      } else if(!strncmp(&command[6], "Last", 4)) {
        deleteLast(head);
      } else if(command[6] == '\0') {
        delete(head, n);
      } else { printf("err2\n"); return 0; }
    } else {
      printf("err\n");
      return 0;
    }
  }
  print_list(head);
  return 0;
}
