function main(input){
    let lines = input.split("\n");
    let length = parseInt(lines[0]);
    let orders = lines.slice(1);
    let put="";
    
    for(let i=0;i<length;i++){
        let order = orders[i].split(" ")[0];
        let key = orders[i].split(" ")[1];
        
        if(order==="insert"){
            if(put===""){
                put=key;
            }else{
            put = key+" "+put;
                
            }
        }else if(order==="delete"){
            let list = put.split(" ");
            let index = list.indexOf(key);
            if(index!==-1){
                list.splice(index,1);
                put = list.join(" ");
            }
        


            
        }else if(order==="deleteFirst"){
            while(!isNaN(parseInt(put[0]))){
                put=put.slice(1);
            }
            put = put.trim();
        }else if(order==="deleteLast"){
            while(!isNaN(parseInt(put[put.length-1]))){
                put=put.slice(0,-1);
            }
            put=put.trim();
        }
    }
    
    
    console.log(put.trim());
    
}




main(require("fs").readFileSync("/dev/stdin","utf-8"));
