import Foundation

func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nmx = readInts()
    let (n,m,x) = (nmx[0],nmx[1],nmx[2])
    var books = [[Int]]()
    
    
    for _ in 0..<n{
        let book = readInts()
        books.append(book)
        
    }
    books.sort(by: {$0[0] < $1[0]})
    print("sort",books)
    
    
    for i in 0..<n-1 {
        for j in i+1..<n {
            for k in 1..<m {
                print("\(i)冊目と\(j)冊目の\(j)行の比較")
                if books[i][k] + books[j][k] < x {
                    print("[条件に合いません]")
                    break
                }
                if k == m-1{
                    print(books[i][0] + books[j][0])
                    return
                }
            }
        }
    }
    print(-1)
}

main()
