import sys input = sys.stdin.readline from collections import deque N,M,K=map(int,input().split()) MAP=[list(map(int,input().split())) for i in range(N)] OK=0 NG=10**9+1 while NG>OK+1: mid=(OK+NG)//2 DP=[[1<<63]*M for i in range(N)] if MAP[0][0]DP[x][y]+1: DP[z][w]=DP[x][y]+1 Q.append((z,w)) else: if DP[z][w]>DP[x][y]: DP[z][w]=DP[x][y] Q.appendleft((z,w)) if DP[-1][-1]<=K: OK=mid else: NG=mid print(OK)