#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node *link;
struct node
{ int v; link next; };

link insert(int v, link next){ 
	link x = malloc(sizeof(*x));
	x->v = v; x->next = next;     
	return x;                         
}

link delete(int v, link x){
	link head,t,temp;
	head=x;
	if(head->v==v){
		temp=head->next;
		free(head);
		head=temp;
	}else{
		for(t=head;t!=NULL;t=t->next){
			if(t->next->v==v){
				temp=t->next;
				t->next=temp->next;
				break;
			}
		}
		free(temp);	
	}
	
	return head;
}

link deleteLast(link x){
	link head,t,temp;
	head=x;
	if(head==NULL)return NULL;
	if(head->next==NULL){
		free(head);
		return NULL;
	}
	for(t=head;t!=NULL;t=t->next){
		if(t->next->next==NULL){
			free(t->next->next);
			t->next=NULL;
			break;
		}		
	}
	return head;
}

void Print(link x){
  link head,t;
  head=x;
	for(t=head;t!=NULL;t=t->next){
		if(t->next==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}

void FreeList(link x){
	link next;
	while(x->next!=NULL){
		next=x->next;
		free(x);
		x=next;
	}
}

int main(void){
	int n,i;
	char c[20];
	int x;
	link p=NULL,temp;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",c);
		
		if(!strcmp(c,"insert")){
			scanf("%d",&x);
			p=insert(x,p);
		}else if(!strcmp(c,"delete")){
			scanf("%d",&x);
			p=delete(x,p);
		}else if(!strcmp(c,"deleteFirst")){
			temp=p->next;
			free(p);
			p=temp;
		}else if(!strcmp(c,"deleteLast")){
			p=deleteLast(p);
		}
		
	}
	Print(p);
	FreeList(p);
	return 0;
}