var fs = require('fs');

var lines = fs.readFileSync("/dev/stdin", "utf8").split('\n');
lines.shift();
console.log(lines);
var ary = [];

var funcs = {
    'insert': insert,
    'delete': remove,
    'deleteFirst': removeFirst,
    'deleteLast': removeLast
};

lines.forEach(function(l) {
    var spl = l.split(' ');
    var inst = spl[0];
    var arg = spl[1];

    funcs[inst] && funcs[inst](arg);
});

console.log(ary.join(' '));

function insert(n) {
    ary.unshift(parseInt(n));
};

function remove(n) {
    var idx = ary.indexOf(parseInt(n));
    if (idx > 0) {
        ary.splice(idx, 1);
    }
}

function removeFirst() {
    ary.shift();
}

function removeLast() {
    ary.pop();
}