# frozen_string_literal: true

n = gets.to_i
list = []
n.times do
  query = gets.split(' ')
  case query[0]
  when 'insert'
    list.unshift(query[1])
  when 'delete'
    if (k = list.index(query[1]))
      list.delete_at(k)
    end
  when 'deleteFirst'
    list.shift
  when 'deleteLast'
    list.pop
  end
end
puts list.join(' ')

