import heapq N, M, K = map(int, input().split()) A = [list(map(int, input().split())) for i in range(N)] def slove(grid, N, M, K, X): directions = [(-1, 0), (1, 0), (0, -1), (0, 1)] changeCount = [[10 ** 18] * M for i in range(N)] changeCount[0][0] = 0 if grid[0][0] >= X else 1 pq = [(changeCount[0][0], 0, 0)] while pq: currentChange, i, j = heapq.heappop(pq) if i == N - 1 and j == M - 1: return currentChange <= K if currentChange > K: continue for di, dj in directions: ni, nj = i + di, j + dj if 0 <= ni < N and 0 <= nj < M: nextChange = currentChange + (1 if grid[ni][nj] < X else 0) if nextChange < changeCount[ni][nj]: changeCount[ni][nj] = nextChange heapq.heappush(pq, (nextChange, ni, nj)) return False low, high = 1, 10 ** 9 + 1 while low < high: mid = (low + high) // 2 if slove(A, N, M, K, mid): low = mid + 1 else: high = mid print(low - 1)