n, m = gets.split.map(&:to_i)
done = 2 ** n - 1
min_of = [0] + [nil] * done

key_vals = m.times.map{|i|
    price, count = gets.split.map(&:to_i)
    val = gets.split.map(&:to_i).inject(0){|acc, it| acc + 2 ** (it - 1)}
    min_of[val] = price
    val
}

(0...(min_of.size)).each{|m_val|
    key_vals.each{|k_val|
        next if min_of[m_val] == nil
        val = m_val | k_val
        cost = min_of[m_val] + min_of[k_val]
        if min_of[val] == nil || min_of[val] > cost
            min_of[val] = cost
        end
    }
}

if min_of[done] == nil
    puts -1
else
    puts min_of[done]
end