n = gets.to_i

a = []

n.times{|i|
    a[i] = gets.chomp
}

ary = []

n.times{|i|
    break if ary.length > 1000000
    x = a.shift
    case x
    when "deleteFirst" then
        ary.shift
    when "deleteLast" then
        ary.pop
    else
        cmd = x.split[0]
        i = x.split[1].to_i
        case cmd
        when "insert" then
            ary.unshift(i)
        when "delete" then
            if (index = ary.index(i)) != nil then
                ary.delete_at(index)
            end
        end
    end
}

puts ary.join(" ")
