#include<iostream>
#include<cstdlib>
using namespace std;

struct node{
	int num;
	node* next;
	node* prev;
};

int main(){

	
	int order_num;
	char order[10];
	int val;
	node* p = (node*)malloc(sizeof(node));
	node* origin = p;
	cin >> order_num;
	int test = order_num;

	for(int i = 0; i < test; i++){
		cin >> order;	
		if(order[0] == 'i'){
			cin >> val;
			p->num = val;
			p->next = (node*)malloc(sizeof(node)); 
			p->next->prev = p;
			p = p->next;
		}else if(strcmp(order,"delete") == 0){
			cin >> val;
			node* p2 = origin;
			while(p2->next != NULL){
				if(p2->num == val){
					if(p2->prev == NULL){
						origin = origin->next;
						free(origin->prev);
						origin -> prev = NULL;
					}else{
						p2->next->prev = p2->prev;
						p2->prev->next = p2->next;
						free(p2);
						break;
					}
				}
				p2 = p2->next;
			}
		}else if(strcmp(order,"deleteFirst") == 0){
			p->prev = p->prev->prev;
			free(p->prev->next);
			p->prev->next = p;
		}else if(strcmp(order,"deleteLast") == 0){
			origin = origin->next;
			free(origin->prev);
			origin->prev = NULL;
		}
	}
	p = p->prev;
	while(p->prev != NULL){
		free(p->next);
		cout << p->num << " ";
		p = p->prev;
	}
	cout << p->num << endl;
	free(p);


	
	return 0;
}