var L=0;
function DoublyLinkedList() {
    this.H = null;
    this.T = null;
}
DoublyLinkedList.prototype={
    add: function(value){
        var node={value:value,N:null,P:null,}
        if(L==0){this.H=node;this.T=node;}
        else {this.T.N=node;node.P=this.T;this.T=node;}
        L++;
    },
    insert: function(value){
        var node={value:value,N:null,P:null,}
        if(L==0){this.H=node;this.T=node;}
        else{this.H.P=node;node.N=this.H;this.H=node;}
        L++;
    },
    getNode: function(index){
        var node=this.H;
        var i=0;
        while(i++<index){node=node.N;}
        return node;
    },
    remove: function(index){
        var node=this.H;
        var i=0;
        if(index==0){
            this.H=node.N;
            if(this.H==null){this.T=null;}
            else{this.H.P=null;}
        }
        else if(index==L-1){
            node=this.T;
            this.T=node.P;
            this.T.N=null;
        }
        else{
            while(i++<index){node=node.N;}
            node.P.N=node.N;
            node.N.P=node.P;
        }
        L--;
    },
    delete: function(value){
         for(var i=0;i<L;i++){
            if(list.getNode(i).value==value){list.remove(i);break;}
         }
    },
    deleteFirst: function(){
         var node=this.H;
         this.H=node.N;
         if(this.H==null){this.T=null;}
         else{this.H.P=null;}
         L--;
    },
    deleteLast: function(){
         var node=this.T;
         this.T=node.P;
         if(this.T==null){this.H=null;}
         else{this.T.N=null;}
         L--;
    },
    printList: function(){
         var str="";
         for(var i=0;i<L;i++){str+=list.getNode(i).value+" ";}
         console.log(str.slice(0,-1));
    }
};
var list = new DoublyLinkedList();
 
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
for(var i=0;i<n;i++){
   var arr=Arr[i].split(" ");
   switch (arr[0]){
      case "insert":list.insert(arr[1]-0);break;
      case "delete":list.delete(arr[1]-0);break;
      case "deleteFirst":list.deleteFirst();break;
      case "deleteLast":list.deleteLast();break;
   }
}
list.printList();