'use strict'

class List {
    constructor()
    {
        const n = new Node;
        n.prev = n;
        n.next = n;
        this.nil = n;
    }

    insert(x)
    {
        const n = new Node(x);
        this.nil.next.prev = n;
        n.next = this.nil.next;
        this.nil.next = n;
        n.prev = this.nil
    }

    search(x)
    {
        let node = this.nil.next
        while(node.key !== null && node.key !== x){
            node = node.next;
        }
        return node
    }

    delete(x)
    {
        this.deleteNode(this.search(x))
    }
    
    deleteNode(node)
    {
        if(node.key === null){
            return
        }
        node.prev.next = node.next
        node.next.prev = node.prev
    }

    deleteFirst()
    {
        this.deleteNode(this.nil.next)
    }

    deleteLast()
    {
        this.deleteNode(this.nil.prev)
    }

    print()
    {
        let node = this.nil.next;
        let str = ''
        for(let i = 0; node.key !== null; i++){
            if(i > 0){
                str += ' '
            }
            str += node.key.toString()
            node = node.next
        }
        return str
    }
}

class Node {
    constructor(key = null, prev = null, next = null)
    {
        this.key = key;
        this.prev = prev;
        this.next = next;
    }
}


const main = (input) => {
    input = input.split('\n')
    const n = parseInt(input[0])
    const com = input.slice(1, n + 1)
    const list = new List;
    com.forEach(v => {
        if(v[0] === 'i'){
            const num = parseInt(v.split(' ')[1])
            list.insert(num)
        }else{
            if(v === 'deleteFirst'){
                list.deleteFirst()
            }else if(v === 'deleteLast'){
                list.deleteLast()
            }else{
                const num = parseInt(v.split(' ')[1])
                list.delete(num)
            }
        }
    })
    console.log(list.print())
}

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