fun main() {
    val l = readLine()!!.split(' ').map { it.toInt() }
    val map: MutableMap<Int, Int> = mutableMapOf()
    (1..l[1]).forEach{ map[it] = l[2] }

    val list: MutableList<Pair<Int, List<Int>>> = mutableListOf()
    for (i in 0 until l[0]) {
        var line = readLine()!!.split(' ').map { it.toInt() }.toMutableList()
        val c = line[0]
        line.removeAt(0)
        list.add(c to line)
    }

    var min = Int.MAX_VALUE
    var find = false
    fun search(tmpMap: MutableMap<Int, Int>, tmpMin: Int, x: Int) {
        if (x < l[0]-1) search(tmpMap.toMap().toMutableMap(), tmpMin, x+1)

        for (y in 0 until l[1]) {
            tmpMap[y+1] = tmpMap[y+1]!! - list[x].second[y]
        }

        if (tmpMap.all { it.value < 1 }) {
            min = Math.min(min, tmpMin+list[x].first)
            find = true
        } else {
            if (x < l[0]-1) search(tmpMap.toMap().toMutableMap(), tmpMin+list[x].first, x+1)
        }
    }

    search(map.toMap().toMutableMap(), 0, 0)

    println(if (find) min else -1)
}
