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

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

typedef struct node * NodePointer;

NodePointer nil;

NodePointer root;

NodePointer malloc_node (void )
{
	NodePointer ptr = (NodePointer) malloc (sizeof(int) );
	
	return ptr;
}

void free_node (NodePointer ptr )
{
	free (ptr );
	return;
}

NodePointer make_node (int key )
{
	NodePointer curr = malloc_node (); 
	curr->key = key;
	curr->next = NULL;
	curr->prev = NULL;

	return curr;
}

void init (void )
{
	root = make_node (-1 );
	nil = root;
}

void insert (int key )
{
	NodePointer next_node = malloc_node();
	next_node->key = key;
	next_node->next = NULL;
	next_node->prev = nil;
	nil->next = next_node;
	nil = next_node;
}

void delete (int key )
{
	NodePointer search = nil;

	while (1 ){
		if (search->key == key ){
			if (search == nil ){	// ???????????´???
				nil = search->prev;
				free_node (search );
				break;
			}else{
				NodePointer p = search->prev;
				NodePointer n = search->next;
				p->next = n;
				n->prev = p;
				free_node (search );
				break;
			} // end if
		} // end if
		search = search->prev;
	} // end while								
}

void deleteFirst (void )
{
//	nil->next = NULL;
	NodePointer t = nil;
	t->prev->next = NULL;
	nil = nil->prev;
	free_node (t );
}

void deleteLast (void )
{
	NodePointer t = root->next;
	if (t != nil ){
		root->next = t->next;
		t->next->prev = root;
		free_node (t );
	}else{
		free_node (nil );
		nil = root;
		root->next = NULL;
	} // end if		
}

void disp_node (void )
{
	if (nil == root ) {
		printf ("\n" );
		return;
	} // end if

	while (1 ){
		printf ("%d", nil->key );
		if (nil->prev != root ){
			printf (" " );
			nil = nil->prev;
		}else{
			printf ("\n" );
			break;
		} // end if
	} // end while
}

int main(){

	char com[12];
	int i, n, key;
	scanf("%d", &n);
	init();

	for ( i = 0; i < n; i++ ){
		scanf("%s %d", com, &key);
	    if ( com[0] == 'i' ) {
			insert(key);
		}else
		if ( com[0] == 'd' ) {
      		if (strlen(com) > 6 ){
				if (com[6] == 'F' ) {
					deleteFirst();
				}else
				if( com[6] == 'L' ) {
	  				deleteLast();
				} // end if
      		}else{
				delete(key);
			} // end if
		} // end if
	} // end for

	disp_node ();

	return 0;
}