N,M=gets.chomp.split(" ").map(&:to_i)
keys = [] # [cost, key(bit), keys]
M.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    array=gets.chomp.split(" ").map(&:to_i)
    key = 0
    array.each do |i|
        key += 2**(i-1)
    end
    keys.push([a, key, array])
end
keys = keys.sort_by { |e| e[0] }

all_key = 0
keys.each do |e|
    all_key = all_key | e[1]
end
if all_key != (2**N)-1
    puts "-1"
    exit
end

ret = 0
rest_key = (1..N).to_a
got_key = 0
# must key
(1..N).each do |i|
    selected = keys.select { |e| (e[1] & 2**(i-1))!=0 }
    if selected.length == 1
        key = selected[0]
        ret += key[0]
        key[2].each {|k| rest_key.delete(k) }
        got_key = got_key | key[1]
        keys.delete(key)
    end
end

rest_key_list = rest_key.map do |e|
    keys.select { |key| key[2].include?(e) }
end


def rrr(rest_key_list, orders)
    if rest_key_list.length == orders.length
        val = 0
        orders.uniq.each do |order|
            val += order[0]
        end
        return val
    end


    orders.length
    target_keys = rest_key_list[orders.length]
    val = rrr(rest_key_list, orders.dup.push(target_keys[0]))
    target_keys.each do |target_key|
        v = rrr(rest_key_list, orders.dup.push(target_key))
        val = v if v < val
    end
    return val
end
ret += rrr(rest_key_list, [])

puts ret