# coding: utf-8 # Your code here! N,M,K=map(int,input().split()) l=[] for _ in range(N): l.append(list(map(int,input().split()))) dp=l[0] ans=0 for i in range(1,N): temp=[] for item in dp: for num in l[i]: temp.append(item+num) dp=temp[:] ans=0 for item in dp: if item<=K: ans=max(ans,item) if ans==0: print(-1) else: print(K-ans)