const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

class Node {
    constructor(n) {
        this.value = n;
        this.prev = null;
        this.next = null;
    }
}

class List {
    constructor() {
        this.size = 0;
        this.head = null;
        this.tail = null;
    }

    insert(n) {
        const newNode = new Node(n);
        if (this.size === 0) {
            this.head = newNode;
            this.tail = newNode;
        } else {
            newNode.next = this.head;
            this.head.prev = newNode;
            this.head = newNode;
        }
        this.size++;
    }

    del(n) {
        let delNode = this.head;
        while(delNode.value !== n) {
            delNode = delNode.next;
        }
        if (delNode.prev !== null) delNode.prev.next = delNode.next;
        else this.head = delNode.next;
        if (delNode.next !== null) delNode.next.prev = delNode.prev;
        else this.tail = delNode.prev;
        
        this.size--;
    }

    deleteFirst() {
        this.head = this.head.next;
        this.head.prev = null;
        this.size--;
    }

    deleteLast() {
        this.tail = this.tail.prev;
        this.tail.next = null;
        this.size--;
    }

    toArray() {
        let currentNode = this.head;
        const arr = [];
        while(currentNode !== null) {
            arr.push(currentNode.value);
            currentNode = currentNode.next;
        }

        return arr;
    }
}


const cmds = line.slice(1);
const ans = cmds.reduce((acc, x) => {
    const cmd = x.split(' ');
    switch (cmd[0]) {
        case 'insert':
            acc.insert(parseInt(cmd[1]));
            break;
        case 'delete':
            acc.del(parseInt(cmd[1]));
            break;
        case 'deleteFirst':
            acc.deleteFirst();
            break;
        case 'deleteLast':
            acc.deleteLast();
            break;
    }

    return acc;
}, new List()).toArray().map(x => x.toString()).join(' ');

console.log(ans);

