#include<stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
 
using namespace std;
 
#define BUF_SIZE 1024
 
struct Node{
    int data;
    Node* prev;
    Node* next;
};
 
class ConnectedList{
public:
    ConnectedList(){
        motherNode = new Node();
        motherNode->data = -1;
        motherNode->prev = motherNode;   
        motherNode->next = motherNode;
    };
    ~ConnectedList(){
        Node* tmpNode = motherNode->next;
        Node* nextNode;
        while(tmpNode != motherNode){
            nextNode = tmpNode->next;
            delete tmpNode;
            tmpNode = nextNode;
        }
        delete motherNode;
    };
    void insertNode(int x){
        Node* tmpNode = motherNode->next;
        motherNode->next = new Node();
        motherNode->next->data = x;
        motherNode->next->next = tmpNode;
        motherNode->next->prev = motherNode;
        tmpNode->prev = motherNode->next;
    };
    void deleteNode(int x){
        Node* tmpNode = motherNode->next;
        while(tmpNode != motherNode && tmpNode->data != x){
            tmpNode = tmpNode->next;
        }
        if(tmpNode != motherNode){  
            tmpNode->prev->next = tmpNode->next;
            tmpNode->next->prev = tmpNode->prev;
            delete tmpNode;
        }
    };
 
    void deleteFirst(){
        Node* tmpNode = motherNode->next;
        motherNode->next = motherNode->next->next;
        motherNode->next->prev = motherNode;
        delete tmpNode; 
    };
 
    void deleteLast(){
        Node* tmpNode = motherNode->prev;
        motherNode->prev = motherNode->prev->prev;
        motherNode->prev->next = motherNode;
        delete tmpNode; 
    };
 
    void showList(){
        Node* tmpNode = motherNode->next;
        printf("%d",tmpNode->data);
        tmpNode = tmpNode->next;
        while(tmpNode != motherNode){
            printf(" %d",tmpNode->data);
            tmpNode = tmpNode->next;
        }
        printf("\n");
    }
 
private:
    Node* motherNode;
};
 
 
int main(){
 
    char buf[BUF_SIZE];
    int n = atoi(fgets(buf,BUF_SIZE,stdin));
 
    ConnectedList list;
 
    for(int i = 0; i < n; i++){
 
        fgets(buf,BUF_SIZE,stdin);
 
        if(buf[6] == 'F'){
            list.deleteFirst();
        }else if(buf[6] == 'L'){
            list.deleteLast();
        }else{
            int S = 0;
             
            if(buf[0] == 'i'){  //insert x
 
                for(int i = 0; buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.insertNode(S);
            }else{  
                for(int i = 0;buf[i] != '\0';i++){
                    if(buf[i] >= '0' && buf[i] <= '9'){
                        S = 10*S + (buf[i] - '0');
                    }
                }
                list.deleteNode(S);
            }
 
        }
 
    }
 
    list.showList();
 
}