from sys import stdin def main(): input = lambda: stdin.readline()[:-1] N, M, K = map(int, input().split()) A = [tuple(map(int, input().split())) for _ in [0] * N] for idx in range(M): sum_ = 0 for i in range(N): sum_ += A[i][idx] if sum_ >= K: break ans = float('inf') for mask in range(1 << N): n = sum_ for i in range(N): if mask & 1 << i: n -= A[i][idx] - A[i][idx-1] if n <= K: ans = min(ans, K - n) if ans == float('inf'): print(-1) else: print(ans) main()