N,M,K = map(int,input().split()) A = [] for _ in range(N): a = list(map(int,input().split())) a.sort(reverse=True) A.append(a) ans = 0 def perm(n,s): global ans if n == N: ans = max(ans,s) return for a in A[n]: if s+a > K: continue perm(n+1,s+a) perm(0,0) if ans == 0: print(-1) else: print(K-ans)