/* ALDS1_3_C: Doubley Linked List */
/* 20181115 AOJ */

#define _CRT_SECURE_NO_WARNINGS

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

typedef struct Node_{
	int key;
	struct Node_ *prev;
	struct Node_ *next;
} Node;

Node *nil ;

void initList();
void insertKey(int key);
Node *listSearch(int key);
void deleteNode(Node *node);
void deleteKey(int key);
void deleteFirst();
void deleteLast();
void printList();

int main(void){
	int n, key, i = 0;
	char cmd[12];

	initList();
	scanf("%d", &n);
	 
	while((i++) < n){
		scanf("%s%d", cmd, &key);
		if(cmd[0] == 'i'){
			insertKey(key);
		}else if(cmd[0] == 'd' && cmd[6] == 0){
			deleteKey(key);
		}else if(cmd[6] == 'F'){
			deleteFirst();
		}else if(cmd[6] == 'L'){
			deleteLast();
		}else{
			/* Do nothing */
		}
	}

    printList();

	return 0;
}

void initList(){
	nil = (Node *)malloc(sizeof(Node));
	nil->key = 0;
	nil->next = nil;
	nil->prev = nil;
}

void insertKey(int key){
	Node *node = (Node *)malloc(sizeof(Node));

	node->key = key;
	node->next = nil->next;
	nil->next->prev = node;
	nil->next = node;
	node->prev = nil;
}

Node* listSearch(int key){
	Node *curNode = nil->next;

	while(curNode != nil && curNode->key != key){
		curNode = curNode->next;
	}

	return curNode;
}

void deleteNode(Node *node){
	if(node == nil) return;
	node->prev->next = node->next;
	node->next->prev = node->prev;
	free(node);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);	
}

void printList(){
	Node *curNode = nil->next;

	while(curNode != nil){
		printf("%d", curNode->key);
		curNode = curNode->next;
		if(curNode != nil){
			printf(" ");
		}else{
			printf("\n");
		}
	}
}
