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)

  av_cost = cost / boxes.length.to_f
  costs.push([av_cost, cost, boxes])

  all_boxes.concat(boxes)
  all_boxes
end

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

total_cost = 0

costs.sort_by!(&:first)

boxes = (1..n).to_a

costs.each do |_, cost, bs|
  break if boxes.empty?

  unless (boxes & bs).empty?
    total_cost += cost
  end
  boxes = boxes - bs
end

puts total_cost
