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

typedef struct item {
	struct item *next;
	int value;
} item;

int main(void) {
	char s[100];
	int n, val, i, j;
	item *itm, *itm1, *first = NULL;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		itm = first;
		if (strcmp(s, "insert") == 0) {
			scanf("%d", &val);
			itm = calloc(1, sizeof(item));
			itm->value = val;
			itm->next = first;
			first = itm;
		} else if (strcmp(s, "delete") == 0) {
			scanf("%d", &val);
			itm1 = NULL;
			while (itm != NULL && itm->value != val) {
				itm1 = itm;
				itm = itm->next;
			}
			if (itm1 == NULL) {
				first = itm->next;
				free(itm);
			} else if (itm != NULL) {
				itm1->next = itm->next;
				free(itm);
			}
		} else if(strcmp(s, "deleteFirst") == 0) {
			if (itm != NULL) {
				first = itm->next;
				free(itm);
			}
		} else if(strcmp(s, "deleteLast") == 0) {
			itm1 = NULL;
			while (itm != NULL && itm->next != NULL) {
				itm1 = itm;
				itm = itm->next;
			}
			if (itm1 != NULL) {
				itm1->next = NULL;
				free(itm);
			}
		} else printf("invalid %s\n", s);
	}
	for (itm = first; itm != NULL; itm = itm->next) {
		if (itm != first) printf(" ");
		printf("%d", itm->value);
	}
	printf("\n");
}