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

typedef struct node {
	struct node *next, *prev;
	int key;
} LINKEDLIST;

void insert(int key);
void delete(int key);
void deleteFirst();
void deleteLast();
void printList();

int node_cnt = 0;
LINKEDLIST *head = NULL;

int main(void)
{
	int n;								// ????????°
	scanf("%d", &n);

	char command[12];					// ?????????????´?
	int key, i;
	for (i=0; i<n; i++) {
		scanf("%s", command);
		if (command[0] == 'i') {		// command == "insert"
			scanf("%d", &key);
			insert(key);
		} else if (command[6] == 'F') {	// command == "deleteFirst"
			deleteFirst();
		} else if (command[6] == 'L') {	// command == "deleteLast"
			deleteLast();
		} else {						// command == "delete"
			scanf("%d", &key);
			delete(key);
		}
	}

	printList();

	return 0;
}

// add a new node at the head of the list
void insert(int key) {
	LINKEDLIST *node;
	node = malloc(sizeof(LINKEDLIST));
	(*node).key = key; 					// same as "node->key = key;"
	(*node).next = head;				// head contains the non-renewed value
	(*node).prev = NULL;
	if (head != NULL)
		(*((*node).next)).prev = node;
	head = node;
	node_cnt++;
}

void deleteFirst() {
	LINKEDLIST *point = head;
	if ((*head).next != NULL) {
		head = (*head).next;
		(*head).prev = NULL;
	} else {
		head = NULL;
	}
	free(point);
	node_cnt--;
}

void delete(int key) {
	int i;
	if (head == NULL) return;						// return if there is no entry in list
	LINKEDLIST *point = head;
	for (i=0; i<node_cnt; i++) {
		if ((*point).key == key) {
			if ((*point).prev == NULL) {			// if the node containing the key is the first node
				deleteFirst();
			} else if ((*point).next == NULL) {		// if the node containing the key is the last node
				deleteLast();
			} else {
				(*((*point).prev)).next = (*point).next;
				(*((*point).next)).prev = (*point).prev;
				free(point);
				node_cnt--;
			}
			break;
		} else {
			point = (*point).next;
		}
	}
}

void deleteLast() {
	int i;
	LINKEDLIST *point = head;
	for (i=0; i<node_cnt-1; i++) {
		point = (*point).next;
	}
	if ((*point).prev != NULL)
		(*((*point).prev)).next = NULL;
	else
		head = NULL;
	free(point);
	node_cnt--;
}

void printList() {
	int i;
	LINKEDLIST *point = head;
	for (i=0; i<node_cnt; i++) {
		printf("%d", (*point).key);
		if (i<node_cnt-1)
			putchar(' ');
		point = (*point).next;
	}
	putchar('\n');
}