import sys input = sys.stdin.readline N, M, K = map(int, input().split()) A = [] for i in range(N): A.append(list(map(int, input().split()))) from collections import * def check(mid): inf = 10 ** 18 D = [[inf] * N for _ in range(N)] Q = deque() D[0][0] = int(A[0][0] < mid) dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] Q.append((0, 0)) while Q: px, py = Q.popleft() for k in range(4): x, y = px + dx[k], py + dy[k] if x < 0 or x > N - 1 or y < 0 or y > N - 1: continue if D[x][y] != inf and D[x][y] <= D[px][py] + int(A[x][y] < mid): continue D[x][y] = D[px][py] + int(A[x][y] < mid) if A[x][y] < mid: Q.append((x, y)) else: Q.appendleft((x, y)) return D[N-1][N-1] def BinarySearch(yes = 10 ** 18, no = -1): while abs(yes - no) != 1: mid = (yes + no)//2 if check(mid) <= K: yes = mid else: no = mid return yes print(BinarySearch(1, 10**9+1))