function main(input) {
  const args = input.split('\n')
  const nums = args[0].split(' ')
  const n = Number(nums[0])
  const m = Number(nums[1])
  const x = Number(nums[2])
  const books = args.slice(1, args.length).map(b => b.split(' ').map(v => Number(v)))
  const sortedBooks = books.sort((a, b) => a[0] - b[0])
  let sumA = Array(m).fill(0)
  let sumM = 0;
  let count
  for (let i=0; i < books.length; i++) {
    count = 0
    for (let j=0; j < m; j++) {
      sumA[j] += sortedBooks[i][j+1]
      if (sumA[j] >= x) {
        count++
      }
    }
    sumM += sortedBooks[i][0]
    if (count === m) {
      console.log(sumM)
      break
    }
  }
  console.log(-1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))