let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let M = input[1]
let X = input[2]

struct Book {
    var price: Int
    var contents: [Int]
}

var books = [Book]()
var sumOfComprehension = Array(repeating: 0, count: M)

for _ in 0 ..< N {
    let book = readLine()!.split(separator: " ").map { Int($0)! }
    books.append(Book(price: book[0], contents: Array(book[1 ... M])))
}

func getBestPrice(_ books: [Book]) -> Int? {
    guard books.map({ $0.contents })
        .reduce(Array(repeating: 0, count: M), { zip($0, $1).map({ $0.0 + $0.1 }) })
        .first(where: { $0 < X }) == nil else {
        return nil
    }

    var price = books.map { $0.price }.reduce(0, +)
    for i in 0 ..< books.count {
        let newBooks: [Book]
        if i == 0 {
            newBooks = Array(books[1 ..< books.count])
        } else if i == books.count - 1 {
            newBooks = Array(books[0 ..< books.count - 1])
        } else {
            newBooks = Array(books[0 ..< i] + books[i + 1 ..< books.count])
        }
        if let bestPrice = getBestPrice(newBooks) {
            price = min(price, bestPrice)
        }
    }
    return price
}

print(getBestPrice(books) ?? "-1")
