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

typedef struct node {
  char key[11];
  struct node *next;
  struct node *prev;
} Node;

int main(){
  int i;
  char key[11];
  Node nil, *np;
  char buf[32];
  fgets(buf, 32, stdin);
  Node *pool = (Node*)malloc(sizeof(Node)*1500000);
  int plen=0;

  nil.next = nil.prev = &nil;
  
  while (fgets(buf, 32, stdin)) {
    if (buf[0]=='i') { // insert key
      for (i=0; buf[i+7]!='\n'; pool[plen].key[i]=buf[i+7],i++);
      pool[plen].key[i]=0;
      pool[plen].prev = &nil;
      pool[plen].next = nil.next;
      nil.next = nil.next->prev = &pool[plen];
      plen++;
    } else if (*buf == 'd') {
      if (buf[6] != ' ') {
	if (buf[6] == 'F') { //deleteFirst();
	  if (nil.next!=&nil) {
	    np = nil.next;
	    np->prev->next = np->next;
	    np->next->prev = np->prev;
	  }
	} else {//if (buf[6] == 'L') {// deleteLast();
	  if (nil.prev!=&nil) {
	    np = nil.prev;
	    np->prev->next = np->next;
	    np->next->prev = np->prev;
	  }
	}
      } else { // delete x
	for (i=0; buf[i+7]!='\n'; key[i]=buf[i+7],i++);
	key[i]=0;
	for (np=nil.next; np!=&nil; np=np->next) {
	  if (strcmp(np->key,key)==0) {
	    np->prev->next = np->next;
	    np->next->prev = np->prev;
	    break;
	  }
	}
      }
    }
  }

  np = nil.next;
  if (np!=&nil) fputs(np->key, stdout);
  for (np=np->next; np!=&nil; np=np->next) {
    putc_unlocked(' ', stdout);
    fputs(np->key, stdout);
  }
  putc_unlocked('\n', stdout);
  return 0;
}

