fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val a = Array(M) {0}
    val b = Array(M) {0}
    val c = Array(M) { Array(0) {0} }
    val mk = Array(M) { 0 }

    for (i in a.indices) {
        val (s, t) = readLine()!!.split(" ").map{it.toInt()}
        a[i] = s
        b[i] = t
        c[i] = readLine()!!.split(" ").map{it.toInt()}.toTypedArray()
        mk[i] = c[i].fold(0) { s, v -> s or (1 shl v - 1) }
    }
    val INF = 1e9.toInt()
    val dp = Array(1 shl N) { INF }
    dp[0] = 0

    for (s in dp.indices) {
        for (j in a.indices) {
            dp[s or mk[j]] = Math.min(dp[s or mk[j]], dp[s] + a[j])
        }
    }

    println(if(dp.last() < INF) dp.last() else -1)
}
