from collections import deque from collections.abc import Iterator def neighbors4(r: int, c: int) -> Iterator[tuple[int, int]]: for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nr = r + dr nc = c + dc if not (0 <= nr < N and 0 <= nc < M): continue yield nr, nc INF = 1 << 60 N, M, K = map(int, input().split()) A = [] for _ in range(N): A.append(list(map(int, input().split()))) # 最小スコア m として到達可能か?(K 回だけマスを書き換え可能) def bfs01(m: int) -> bool: g = [[INF] * M for _ in range(N)] q = deque([(0, 0)]) g[0][0] = 1 if A[0][0] < m else 0 while q: r, c = q.popleft() if r == N-1 and c == M-1: break for nr, nc in neighbors4(r, c): if g[nr][nc] != INF: continue if A[nr][nc] < m: g[nr][nc] = g[r][c] + 1 q.append((nr, nc)) else: g[nr][nc] = g[r][c] q.appendleft((nr, nc)) return g[N-1][M-1] <= K lo = 1 hi = 10 ** 9 ans = lo while lo <= hi: m = (lo + hi) // 2 if bfs01(m): lo = m + 1 ans = max(ans, m) else: hi = m - 1 print(ans)