N,M,K=map(int,input().split()) SET={0} import copy for i in range(N): NSET=set() A=list(map(int,input().split())) for a in A: for s in SET: if s+a<=K: NSET.add(s+a) SET=NSET #print(SET) if SET==set(): print(-1) else: print(K-max(SET))