#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 200000

struct node{
int key;
struct node *next;
struct node *prev;
};
typedef struct node * NodePointer;
NodePointer nil;
int num = 0;
void init(){
nil = malloc(sizeof(struct node));
nil->next = nil;
nil->prev = nil;
}

void insert(int key){
NodePointer x;
x = malloc(sizeof(struct node));
x->key = key;
nil->next->prev = x;
x->next = nil->next;
nil->next = x;
x->prev = nil;
if(num == 0) nil->prev = x;
num++;
}

void delete(int key){
int i=0;
NodePointer cur = nil;
if(key == -1){
nil->next = nil->next->next;
nil->next->next->prev = nil;
}
else if(key == -2){
nil->prev = nil->prev->prev;
nil->prev->next = nil;
/*
while(cur->next->next != nil) cur = cur->next;
cur->next = nil;
*/
}
else{
while(i < num){
if(cur->next->key == key){
if(cur->next->next == nil){
delete(-2);
return ;
}
cur->next = cur->next->next;
cur->next->prev = cur;
break;
}
cur = cur->next;
i++;
}
}
num--;
}

void printList(){
NodePointer cur = nil->next;
int isf = 1;
while(1){
if ( cur == nil ) break;
if ( isf == 0) printf(" ");
printf("%d", cur->key);
cur = cur->next;
isf = 0;
}
printf("\n");
}

int main(){
int i, n, key;
char s[20];
init();
scanf("%d",&n);
for(i = 0; i < n; i++){
scanf("%s",s);
if(s[0] == 'i'){
scanf("%d",&key);
insert(key);
}
else if(s[0] == 'd'){
if(s[6] == 'F')
delete(-1);
else if(s[6] == 'L')
delete(-2);
else{
scanf("%d",&key);
delete(key);
}
}
}
printList();
free(nil);
return 0;
}