fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val abc = Array(M) {
        val (a, b) = listOfInt()
        var c = 0
        listOfInt(-1).forEach { c = c or (1 shl it) }
        Pair(a, c)
    }
    val INF = 1111111111
    val B = (-1 shl N).inv()
    val dp = IntArray(B + 1) { INF }
    dp[0] = 0
    for (k in abc) {
        for (n in 0..B) {
            dp[n or k.second] = Math.min(dp[n or k.second], dp[n] + k.first)
        }
    }
    println(if (dp[B] != INF) dp[B] else -1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }