list = Array.new(10**6, nil)
first = 0
last = -1

gets.to_i.times {
	d = gets.chomp.split(" ")
	cmd,v = d[0],d[-1]

	case cmd
	when "insert"
		list[last+=1] = v.to_i
	when "delete"
		v = v.to_i
		(first..last).each { |i|
			if list[i] == v
				list[i] = nil
				break
			end
		}
	when "deleteFirst"
		list[first] = nil
		first += 1
	when "deleteLast"
		list[last] = nil
		last -= 1
	end
}
list.compact!.reverse!

list.length.times { |i|
	print " " if not i == 0
	print list[i]
}
puts