function DoublyLinkedList() {
    this.length = 0;
    this.head = null;
    this.tail = null;
}
DoublyLinkedList.prototype={
    add: function(value){
        var node={value:value,next:null,previous:null,}
        if(this.length==0){this.head=node;this.tail=node;}
        else {this.tail.next=node;node.previous=this.tail;this.tail=node;}
        this.length++;
    },
    insert: function(value){
        var node={value:value,next:null,previous:null,}
        if(this.length==0){this.head=node;this.tail=node;}
        else{this.head.previous=node;node.next=this.head;this.head=node;}
        this.length++;
    },
    getNode: function(index){
        var node=this.head;
        var i=0;
        while(i++<index){node=node.next;}
        return node;
    },
    remove: function(index){
        var node=this.head;
        var i=0;
        if(index==0){
            this.head=node.next;
            if(this.head==null){this.tail=null;}
            else{this.head.previous=null;}
        }
        else if(index==this.length-1){
            node=this.tail;
            this.tail=node.previous;
            this.tail.next=null;
        }
        else{
            while(i++<index){node=node.next;}
            node.previous.next=node.next;
            node.next.previous=node.previous;
        }
        this.length--;
    },
    delete: function(value){
         for(var i=0;i<list.length;i++){
            if(list.getNode(i).value==value){list.remove(i);break;}
         }
    },
    deleteFirst: function(){
         var node=this.head;
         this.head=node.next;
         if(this.head==null){this.tail=null;}
         else{this.head.previous=null;}
         this.length--;
    },
    deleteLast: function(){
         var node=this.tail;
         this.tail=node.previous;
         if(this.tail==null){this.head=null;}
         else{this.tail.next=null;}
         this.length--;
    },
    printList: function(){
         var str="";
         for(var i=0;i<list.length;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();