from heapq import * 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 = -1 hq = [(-a,1) for a in A[0]] while hq: i,j = heappop(hq) if j == N: ans = -i break for a in A[j]: if -(i-a) > K: continue heappush(hq,(i-a,j+1)) if ans == -1: print(ans) else: print(K-ans)