fun main(args: Array<String>) {
    abc142e()
}

fun abc142e() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val keys = (1..m).map {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        val c = readLine()!!.split(" ").map { 1 shl (it.toInt() - 1) }.reduce { acc, i -> acc or i }
        Key(a, c)
    }
    val inf = Long.MAX_VALUE / 100000

    val dp = LongArray(5000) { inf }
    dp[0] = 0

    for (key in keys) {
        for (boxes in 0 until (1 shl n)) {
            val canOpenBoxes = boxes or key.targetAsBit
            dp[canOpenBoxes] = Math.min(dp[canOpenBoxes], dp[boxes] + key.price)
        }
    }

    val answer = dp[(1 shl n) - 1].let { if (it < inf) it else -1 }

    println(answer)
}

private data class Key(val price: Int, val targetAsBit: Int)
