N, M, K = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] stack = [(0, 0)] ans = -1 while stack: cp, ck = stack.pop() if cp == N: ans = max(ck, ans) continue for i in range(M): np, nk = cp + 1, ck + A[cp][i] if nk <= K: stack.append((np, nk)) if ans == -1: print(ans) exit() print(K - ans)