class Element {
    constructor(key){
        this.key = key;
        this._prev = null;
        this._next = null;
    }

    getPrev(){
        return this._prev;
    }

    getNext(){
        return this._next;
    }

    setPrev(ele){
        this._prev = ele;
    }

    setNext(ele){
        this._next = ele;
    }
}

class DoublyLinkedList {
    constructor(ele) {
        this.ele = ele;
        this.ele.setNext(this.ele);
        this.ele.setPrev(this.ele);
    }

    insert(key){
        const newEle = new Element(key);
        newEle.setNext(this.ele.getNext());
        this.ele.getNext().setPrev(newEle);
        this.ele.setNext(newEle);
        newEle.setPrev(this.ele);
    }

    listSearch(key){
        let cur = this.ele.getNext();
        while(cur.key !== null && cur.key !== key){
            cur = cur.getNext();
        }
        return cur;
    }

    delete(key){
        const elehaskey = this.listSearch(key);
        this.deleteNode(elehaskey);
    }

    deleteNode(ele){
        if(ele.key === null) return;
        ele.getPrev().setNext(ele.getNext());
        ele.getNext().setPrev(ele.getPrev());
    }

    deleteFirst(){
        this.deleteNode(this.ele.getNext())
    }

    deleteLast(){
        this.deleteNode(this.ele.getPrev())
    }

    showList(){
        let cur = this.ele.getNext();
        const list = [];
        while(cur.key !== null){
            list.push(cur.key);
            cur = cur.getNext();
        }
        return list;
    }

    export(){
        let cur = this.ele.getNext();
        let list = '';
        while(cur.key !== null){
            list += list.length ? ' ' : '';
            list += cur.key.toString();
            cur = cur.getNext();
        }
        console.log(list);
    }

}


function main(stdin) {
    const _inputs = stdin.split("\n");
    const total = parseInt(_inputs.shift(),10);
    const orders = _inputs.filter((e, i) => i < total).map(ele => ele.split(' '));

    const dll = new DoublyLinkedList(new Element(null));
    for(const order of orders){
        if(order[0] === 'insert'){
            dll.insert(order[1]);
        }
        else if(order[0] === 'delete'){
            dll.delete(order[1]);
        }
        else if(order[0] === 'deleteFirst'){
            dll.deleteFirst();
        }
        else if(order[0] === 'deleteLast'){
            dll.deleteLast();
        }
    }
    dll.export();
}



main(require("fs").readFileSync("/dev/stdin", "utf8"));

