fun main(args: Array<String>) {
    val INF = 1001001001
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val keys = mutableListOf<Pair<Int, Int>>()

    val ABC = Array(M) {

        val (A, B) = readLine()!!.split(" ").map(String::toInt)

        // 鍵の集合をBITで表す
        var s = 0
        readLine()!!.split(" ").map(String::toInt).forEach {
            val c = it - 1
            // 論理和で鍵の集合を計算する
            s = s or (1 shl c)
        }
        keys.add(s to A)
    }

    // BIT DP
    // 配るDP
    val dp = IntArray(1 shl N) { INF }

    dp[0] = 0
    for (s in 0 until (1 shl N)) {
        // 鍵
        for (k in keys) {
            // 鍵の組み合わせを論理和
            val t = s or k.first
            val cost = dp[s] + k.second
            dp[t] = Math.min(dp[t], cost)
        }
    }

    val ans = dp.last()
    if (ans == INF) {
        println(-1)
    } else {
        println(ans)
    }
}