#include <stdio.h>

	int p,q;
	int a[9999999];
	
int main() {
	int n;
	scanf("%d",&n);
	while(n--){
		char st[99];
		scanf("%s",st);
		if(st[0]=='i')scanf("%d",a+q++);
		else if(st[6]==0){
			int t;
			scanf("%d",&t);
			for(int idx=q-1;idx>=p;idx--)if(a[idx]==t){
				a[idx]=-1;
				break;
			}
		}else if(st[6]=='F')while(a[--q]==-1);
		else while(a[p++]==-1);
	}
	int f=0;
	for(int i=q-1;i>=p;i--)if(a[i]!=-1)printf(f++?" %d":"%d",a[i]);
	puts("");
}
