n, m = gets.chomp.split.map(&:to_i)

class Key
  attr_accessor :index, :price, :num, :open
  def initialize(index, price, num, open)
    @index = index
    @price = price
    @num = num
    @open = open
  end

  def has_key?(key_num)
    open.include?(key_num)
  end
end

keys = []
1.upto(m) do |i|
  a, b = gets.chomp.split.map(&:to_i)
  c = []
  c = gets.chomp.split.map(&:to_i)
  keys.push(Key.new(i, a, b, c))
end

has_key = []
1.upto(n) do |i|
  has_key[i] = []
end
keys.each do |key|
  1.upto(n) do |i|
    has_key[i].push(key) if key.has_key?(i)
  end
end
has_key.each_with_index do |k, i|
  next if i == 0
  if k.empty?
    p -1
    exit
  end
end

keys.sort! {|a, b| b.price <=> a.price }
keys.each do |key|
  lost = false
  1.upto(n) do |i|
    has_key[i].delete(key)
  end
  has_key.each_with_index do |k, i|
    next if i == 0
    lost = true if k.empty?
  end
  if lost
    1.upto(n) do |i|
      has_key[i].push(key)
    end
  else
    keys.delete(key)
  end
end
sum = 0
keys.each do |key|
  sum += key.price
end
p sum
