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

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

node_t *null;

void init() {
  null = malloc(sizeof(node_t));
  null->prev = null;
  null->next = null;
}

void insert(int key) {
  node_t *x;
  x = malloc(sizeof(node_t));
  x->key = key;
  x->next = null->next;
  null->next->prev = x;
  x->prev = null;
  null->next = x;
  if (x->next == null) {
    null->prev = x;
  }
}

node_t *NodeSearch(int key) {
  node_t *ret = null->next;
  while (ret != null && ret->key != key) {
    ret = ret->next;
  }
  return ret;
}

void delete(node_t *x) {
  if (x == null) return;
  x->next->prev = x->prev;
  x->prev->next = x->next;
  free(x);
}

void deleteFirst() {
  delete(null->next);
}

void deleteLast() {
  delete(null->prev);
}

void PrintNode() {
  node_t *p = null->next;
  while (1) {
    printf("%d", p->key);
    if (p->next == null) break;
    putchar(' ');
    p = p->next;
  }
  putchar('\n');
}

int main() {
  int n;
  int i;
  int key;
  char cmd[20];

  scanf("%d", &n);

  init();

  for (i = 0; i < n; i++) {
    scanf("%s", cmd);
    if (!strcmp(cmd, "insert")) {
      scanf("%d", &key);
      insert(key);
    }
    else if (!strcmp(cmd, "delete")) {
      scanf("%d", &key);
      node_t *tmp = NodeSearch(key);
      delete(tmp);
    }
    else if (!strcmp(cmd, "deleteFirst")) {
      deleteFirst();
    }
    else if (!strcmp(cmd, "deleteLast")) {
      deleteLast();
    }
  }

  PrintNode();
  
  return 0;
}

