#!/usr/bin/env python3
from heapq import heappush, heappop, heapify
# AC in principle, but TLE because python happens to be unreasonably slow.
R, C, K = [int(x) for x in input().split()]

grid = []
for r in range(R): grid.append([int(x) for x in input().split()])

l, h = 0, 1000000000
while l < h:
    m = (l+h+1)//2

    def cost(r, c): return 0 if grid[r][c] >= m else 1
    
    dist = [[R+10 for _ in range(C)] for _ in range(R)]
    q = []
    for i in range(C):
        d = cost(R-1, i)
        dist[R-1][i] = d
        heappush(q, (d, (R-1, i)))

    k = R+10
    while len(q) > 0:
        d, (r, c) = heappop(q)
        if r == 0:
            k = d
            break
        if d != dist[r][c]: continue
        for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
            r2, c2 = r+x, c+y
            if r2 < 0 or c2 < 0 or r2 >= R or c2 >= C: continue
            d2 = d + cost(r2, c2)
            if d2 < dist[r2][c2]:
                dist[r2][c2] = d2
                heappush(q, (d2, (r2, c2)))

    if k <= K: l = m
    else: h = m-1

print(l)
