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

int list[1000020];
int head = 1000019;
int tail = 1000019;

void insert(int x)
{
	list[head] = x;
	head--;
}

void delete(int x)
{
	int i;
	for (i = head + 1; i <= tail; i++) {
		if (list[i] == x) {
			list[i] = -1;
			if(i == tail) {
				tail--;
				while(tail == -1)
					tail--;
			}
			return;
		}
	}
}

void deleteFirst()
{
	while (list[head + 1] == -1)
		head++;
	head++;
	while (list[head + 1] == -1)
		head++;
}

void deleteLast()
{
	while (list[tail] == -1)
		tail--;
	tail--;
	while (list[tail] == -1)
		tail--;
}

int main(void)
{
	int n;
	scanf("%d", &n);
	
	while(n--) {
		char op[12];
		int key;
		scanf("%s", op);
		if (!strcmp(op, "insert")) {
			scanf("%d", &key);
			insert(key);
		} else if (!strcmp(op, "delete")) {
			scanf("%d", &key);
			delete(key);
		} else if (!strcmp(op, "deleteFirst")) {
			deleteFirst();
		} else {
			deleteLast();
		}
	}
	int i;
	for(i = head + 1; i < tail; i++) {
		if (list[i] != -1)
			printf("%d", list[i]);
	}
	if (list[i] != -1)
		printf("%d", list[i]);
	return 0;
}
		
	