from collections import deque n, m, k = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] l, r = 0, 1000000001 while r - l > 1: mid = (l + r) // 2 que = deque() cost = [[-1 for _ in range(m)] for _ in range(n)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] que.append((0, 0, 1 if a[0][0] < mid else 0)) while que: x, y, c = que.popleft() if cost[y][x] != -1: continue cost[y][x] = c for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < m and 0 <= ny < n and cost[ny][nx] == -1: if a[ny][nx] < mid: que.append((nx, ny, c + 1)) else: que.appendleft((nx, ny, c)) if cost[n - 1][m - 1] <= k: l = mid else: r = mid print(l)