import os, io; input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline from random import * N, M, C = map(int, input().split()); P = 10**9+7 H = [randint(1, P-1)*P+randint(1, P-1) for _ in range(C)] R = [] for i in range(N): hx = hy = 0 for c in map(int, input().split()): kx, ky = divmod(H[c-1], P); hx = (hx+kx)%P; hy = (hy+ky)%P R += [hx*P+hy] nA = N//2; nB = N-N//2; A = [[] for _ in range(nA+1)]; B = [set() for _ in range(nB+1)] for i in range(1<= len(B): continue for a in A[r]: if (tx-a//P)%P*P+(ty-a)%P in B[z-r]: print(z); exit()