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

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

struct node *head;

void *init()
{
	head = (struct node *)malloc(sizeof(*head));
	head->prev = head;
	head->next = head;
}

struct node *list_search(int key)
{
	struct node *cur = head->next;
	
	if (cur == head)
		return;
	
	while (cur != head && cur->key != key) {
		cur = cur->next;
	}
	
	return cur;
}

void insert(int x)
{
	struct node *n = (struct node *)malloc(sizeof(*n));
	n->key = x;
	
	n->next = head->next;
	n->prev = head;
	head->next->prev = n;
	head->next = n;
}

void delete(struct node *t)
{
	if (t == head)
		return;
	
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void delete_first()
{
	delete(head->next);
}

void delete_last()
{
	delete(head->prev);
}

void walk_list(struct node *head)
{
	struct node *cur = head->next;
	int flag = 0;
	
	if (cur == head)
		return;
	
	while (cur != head) {
		if (flag) printf(" "); 
		printf("%d", cur->key);
		cur = cur->next;
		flag = 1;
	}
}

int main(int argc, char *argv[]) 
{	
	int cc, key;
	char cmd_type[32];
	
	init();
	
	scanf("%d", &cc);
	
	while (cc-- > 0) {
		scanf("%s %d", cmd_type, &key);
		
		if (!strcmp("insert", cmd_type)) {
			insert(key);
		} else if (!strcmp("delete", cmd_type)) {
			delete(list_search(key));
		} else if (!strcmp("deleteFirst", cmd_type)) {
			delete_first();
		} else if (!strcmp("deleteLast", cmd_type)) {
			delete_last();
		}
	}
	
	walk_list(head);
	
	return 0;
}
