from itertools import product import bisect N, M, K = map(int, input().split()) su = [list(map(int, input().split())) for _ in range(N)] s1, s2 = [], [] for v in product(range(M), repeat = N//2): sm = 0 for i in range(N//2): sm += su[i][v[i]] s1.append(sm) for v in product(range(M), repeat=(N+1)//2): sm = 0 for i in range((N+1)//2): sm += su[-1-i][v[i]] s2.append(sm) s2.sort() ans = float('inf') for s in s1: if s > K: continue idx = bisect.bisect_left(s2, K-s) if idx == 0: if K-s-s2[0]>=0: ans = min(ans, K-s-s2[0]) else: continue else: if idx < len(s2) and s2[idx] == K-s: ans = 0 else: ans = min(ans, K-s-s2[idx-1]) if ans == float('inf'): print(-1) else: print(ans)