N,M,K = map(int,input().split()) A = [list(map(int,input().split())) for i in range(N)] dij = [(0,1),(1,0),(0,-1),(-1,0)] from collections import deque INF = 10**18 def is_ok(k): costs = [[INF]*M for i in range(N)] costs[0][0] = int(A[0][0] < k) q = deque([(0,0)]) while q: i,j = q.popleft() if i == N-1 and j == M-1: return costs[-1][-1] <= K for di,dj in dij: ni,nj = i+di,j+dj if not (0 <= ni < N and 0 <= nj < M): continue cost = int(A[ni][nj] < k) if costs[ni][nj] <= costs[i][j] + cost: continue costs[ni][nj] = costs[i][j] + cost if cost: q.append((ni,nj)) else: q.appendleft((ni,nj)) ok = 0 ng = 10**9+1 while ng - ok > 1: mid = (ok+ng)//2 if is_ok(mid): ok = mid else: ng = mid print(ok)