import sys sys.setrecursionlimit(10 ** 6) input = sys.stdin.readline def main(): n, m, k = map(int, input().split()) aa = [list(map(int, input().split())) for _ in range(n)] bfs = set([k]) for i in range(n): nb = set() for x in bfs: for y in aa[i]: s = x - y if s < 0: continue nb.add(s) bfs = nb if bfs: print(min(bfs)) else: print(-1) main()