class Key
    attr_accessor :id, :price, :locks
    def initialize(id, price, locks)
        @id = id
        @price = price
        @locks = locks
    end
end

class Lock
    attr_accessor :id, :keys 
    def initialize(id)
        @id = id
        @keys = []
    end
end

N, M = gets.split.map(&:to_i)
locks = Array.new(N).map.with_index{|a, idx| Lock.new(idx)}
M.times do |m|
    buf1, buf2 = gets.split.map(&:to_i)
    buf3 = gets.split.map(&:to_i).map{|item| item - 1}
    key = Key.new(m, buf1, buf3)
    buf3.each{|cmi| locks[cmi].keys << key}
end

$mins = Hash.new(1000000000)

def calc(sum, unopened_locks)
    if $mins[unopened_locks] < sum
        return sum
    elsif unopened_locks.empty?
        $mins[unopened_locks] = sum
        return sum
    else
        next_lock = unopened_locks[0]
        return next_lock.keys.map{|key| calc(sum + key.price, unopened_locks.reject{|lock| key.locks.include?(lock.id)})}.min
    end
end

p calc(0, locks) || -1