n, m = $stdin.readline.chomp.split(' ').map(&:to_i)

all_boxes = []
costs = []

$stdin.readlines.each_slice(2) do |(key, boxes)|
  cost, _ = key.chomp.split(' ').map(&:to_i)

  boxes = boxes.chomp.split(' ').map(&:to_i)

  costs.push([cost, boxes])

  all_boxes.concat(boxes)
  all_boxes
end

all_boxes.uniq!
if all_boxes.length != n
  puts "-1"
  exit
end

total_cost = 0

boxes = (1..n).to_a

loop do
  break if boxes.empty?

  cost, bs =
    costs.reject { |_, bs| (bs & boxes).empty? }.
    min_by do |cost, bs|
      cost / (bs & boxes).length.to_f
    end

  total_cost += cost
  boxes = boxes - bs
end

puts total_cost
