from sys import stdin pin=stdin.readline def main(): H,W,N=map(int,pin().split()) C=[list(map(int,pin().split()))for _ in[0]*H] d=[[]for _ in[0]*N] for i in range(H): for j in range(W): C[i][j]-=1 d[C[i][j]].append((i,j)) ans=1 start=0 around=((1,0),(0,1),(-1,0),(0,-1)) for i in range(N): flag=True for x,y in d[i]: for dx,dy in around: if 0<=x+dx