import Foundation

class Book {
    var algoPointList = [Int]()
    var price = 0
    init (price: Int, algo: [Int]){
        self.price = price
        self.algoPointList = algo
    }
}

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

let bookCount = Int(split[0])!
let algoCount = Int(split[1])!
let knowledge = Int(split[2])!

var algoList = [Int]()
var bookList = [Book]()

var goalFlag = false
var sumPrice = 0

for _ in 0...algoCount-1 {
    algoList.append(0)
}

for i in 0...bookCount-1 {
	let input_line: String = readLine()!
    var input_line = ""
    let split: [String] = input_line.components(separatedBy: " ")
    let price = Int(split[0])!
    var algoPointList = [Int]()
    for i in 0...algoCount-1 {
        algoPointList.append(Int(split[i+1])!)
    }
    let book = Book(price: price, algo: algoPointList)
    bookList.append(book)
}

bookList.sort(by: {$0.price / $0.algoPointList.reduce(0){ $0 + $1 } < $1.price / $1.algoPointList.reduce(0){ $0 + $1 }})
//print(bookList[0].price / bookList[0].algoPointList.reduce(0){ $0 + $1 })
//print(bookList[2].price / bookList[2].algoPointList.reduce(0){ $0 + $1 })
//コスパ順に並べてみる＞？
//bookList.sort(by: {$0.price < $1.price})

for book in bookList {
//    print(algoList)
    var isContinue = false
    sumPrice += book.price
    for i in 0...book.algoPointList.count-1 {
        algoList[i] += book.algoPointList[i]
        if algoList[i] < knowledge {
            isContinue = true
        }
    }
    if !isContinue {
        goalFlag = true
        break
    }
}

if goalFlag {
    print(sumPrice)
} else {
    print("-1")
}