#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)return head->next;
	
	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->next==NULL)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);
	}
}

int main(void){
	int n,i;
	char c[20];
	int x;
	link p=NULL;
	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")){
			p=p->next;
		}else if(!strcmp(c,"deleteLast")){
			p=deleteLast(p);
		}
		
	}
	Print(p);
	return 0;
}