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

/* リストの要素を表す構造体 */
typedef struct tagListNode {
  struct tagListNode *prev;     /* 前の要素へのポインタ */
  struct tagListNode *next;     /* 次の要素へのポインタ */
  int data;
} ListNode;

int main(void) {
  ListNode *firstnode, *lastnode, *newnode, *thisnode;
  int n;
  scanf("%d", &n);
  firstnode = lastnode = NULL;
  
  while (n--) {
    int x;
    char command[20];
    scanf("%s", command);

    if (strcmp(command, "insert") == 0) {
      scanf("%d", &x);
      /* 新しいノードを作成 */
      newnode = (ListNode *)malloc(sizeof(ListNode));
      newnode->data = x;
      newnode->prev = NULL;

      if (lastnode != NULL) {
        /* 先頭にノードを追加 */
        firstnode->prev = newnode;
        newnode->next = firstnode;
        firstnode = newnode;
      } else {
        /* 最初の要素だったとき */
        firstnode = lastnode = newnode;
        newnode->prev = NULL;
      }
    } else if (strcmp(command, "delete") == 0) {
      scanf("%d", &x);
      /* xの値をもつノードを探索して削除 */
      for (thisnode = firstnode; thisnode != NULL; thisnode = thisnode->next) {
        if (thisnode->data == x) {
          if (thisnode->prev != NULL) {
            thisnode->prev->next = thisnode->next;
          } else {
            thisnode->next->prev = NULL;
            firstnode = thisnode->next;
          }
          if (thisnode->next != NULL) {
            thisnode->next->prev = thisnode->prev;
          } else {
            thisnode->prev->next = NULL;
            lastnode = thisnode->prev;
          }
          free(thisnode);
          break;
        }
      }
    } else if (strcmp(command, "deleteFirst") == 0) {
      thisnode = firstnode;
      thisnode->next->prev = NULL;
      firstnode = thisnode->next;
      free(thisnode);
    } else if (strcmp(command, "deleteLast") == 0) {
      thisnode = lastnode;
      thisnode->prev->next = NULL;
      lastnode = thisnode->prev;
      free(thisnode);
    }      
  }

  for (thisnode = firstnode; thisnode->next != NULL; thisnode = thisnode->next) {
    printf("%d ", thisnode->data);
  }
  printf("%d\n", thisnode->data);
  
  return 0;
}