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

#define N_MAX 100000
#define NAME_LEN 10
#ifdef DEBUG
#define  DPRINT printf
#else
#define DPRINT(...)
#endif

struct q {
	int val;
	struct q *prev;
	struct q *next;
};

struct q *
find(struct q *head, int arg)
{
	struct q *a;
	for (a = head; a != NULL; a = a->next)
		if (a->val == arg)
			break;

	return a;
}

int
main(void)
{
	/* head <- prev [a] next -> tail */
	int i, n;
	struct q *head = NULL;
	struct q *tail = NULL;
	char cmd[16];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf ("%s", cmd);
		if (cmd[0] == 'i') {
			struct q *a = (struct q *)malloc(sizeof(struct q));

			if (a == NULL)
				return 1;

			DPRINT("insert\n");

			scanf("%d", &a->val);
			if (head == NULL) {
				head = a;
				tail = a;
				a->prev = NULL;
				a->next = NULL;
			} else {
				a->prev = NULL;
				a->next = head;
				head->prev = a;
				head = a;
			}
		} else if (cmd[6] == '\0') {
			int x;
			struct q *a;

			DPRINT("delete\n");

			scanf("%d", &x);
			a = find(head, x);
			if (a == NULL)
				continue;

			struct q *pa = a->prev;
			struct q *na = a->next;
			if (a == head) {
				head = na;
				if (na != NULL)
					na->prev = NULL;
			}
			if (a == tail) {
				tail = pa;
				if (pa != NULL)
					pa->next = NULL;
			}
			if (pa != NULL)
				pa->next = na;
			if (na != NULL)
				na->prev = pa;
			free(a);
		} else if (cmd[6] == 'F') {
			struct q *a = head;

			DPRINT("deleteFirst\n");

			if (a != NULL) {
				if (head == tail) {
					head = tail = NULL;
				} else {
					a->next->prev = NULL;
					head = a->next;
				}
				free(a);
			}
		} else if (cmd[6] == 'L') {
			struct q *a = tail;

			DPRINT("deleteLast\n");

			if (a != NULL) {
				if (head == tail) {
					head = tail = NULL;
				} else {
					a->prev->next = NULL;
					tail = a->prev;
				}
				free(a);
			}
		}
	}

	for (;head != NULL; head = head->next) {
		printf("%d%s", head->val, head->next == NULL ? "" : " ");
	}
	printf("\n");

	return 0;
}

