import kotlin.collections.getValue

data class Key(val cost: Int, val canOpen: Int)

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)

    var canOpenAll = 0.inv().shl(n)

    val keys = Array(m) {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        val canOpen = readLine()!!
            .split(" ")
            .map(String::toInt)
            .fold(0) { r, c -> r or 1.shl(c - 1) }

        canOpenAll = canOpenAll or canOpen

        Key(a, canOpen)
    }

    if (canOpenAll != 0.inv()) {
        println(-1)
        return
    }

    val openAll = 0.inv().shl(n).inv()
    val dp = Array(openAll + 1) { Double.POSITIVE_INFINITY }
    dp[0] = 0.0

    keys.forEach {
        for (state in 0..openAll) {
            val nextState = state or it.canOpen
            val nextCost = dp[nextState]
            val newCost = it.cost + dp[state]
            if (newCost < nextCost) dp[nextState] = newCost
        }
    }

    println(dp[openAll].toInt())
}
