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

struct node {
  int key;
  struct node *next;
};
typedef struct node *NodePointer;

NodePointer insert(int);
NodePointer delete(int);
NodePointer deleteFirst(void);
NodePointer deleteLast(void);
NodePointer finditem(int);
void        listPrint(void);
NodePointer make_1node(int, NodePointer);
NodePointer head;


int main () {
  int i, n, x;
  char str[15];

  head = make_1node(0, NULL);
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", str);
    if (str[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    }
    else if (str[0] == 'd') {
      if(str[6] == '\0') {
        scanf("%d", &x);
        delete(x);
      }
      else if(str[6] == 'F') {
        deleteFirst();
      }
      else {}
      (strcmp("deleteLast", str) == 0)
      deleteLast();
    }
  }

  listPrint();
  return 0;
}


NodePointer insert(int keydata) {
  NodePointer newnode;

  newnode = make_1node(keydata, head->next);
  head->next = newnode;
  return newnode;
}

NodePointer delete(int keydata) {
  NodePointer n, delnode;

  if((n = finditem(keydata)) != NULL) {
    delnode = n->next;
    n->next = delnode->next;
    free(delnode);
    return n;
  }
  else return NULL;
}

NodePointer deleteFirst(void) {
  NodePointer delnode;

  delnode = head->next;
  head->next = delnode->next;
  free(delnode);
  return head;
}


NodePointer deleteLast(void) {
  NodePointer n, delnode;

  for(n = head; n->next->next != NULL; n = n->next) {}
  delnode = n->next;
  n->next = NULL;
  free(delnode);
  return n;
}

NodePointer finditem(int keydata) {
  NodePointer n;

  for(n = head; n->next != NULL; n = n->next) {
    if(n->next->key == keydata) return n;
  }
  return NULL;
}

void listPrint(void) {
  NodePointer n;

  for(n = head->next; n != NULL; n = n->next) {
    if(n != head->next) printf(" ");
    printf("%d", n->key);
  }
  printf("\n");
}

NodePointer make_1node(int keydata, NodePointer p) {
  NodePointer n;

  if((n = (NodePointer)malloc(sizeof(struct node))) == NULL) {
    exit(8);
  }
  n->key = keydata;
  n->next = p;
  return n;
}