#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M,K; cin >> N >> M >> K; vector> A(N,vector(M)); for(auto &h : A) for(auto &w : h) cin >> w; int low = 0,high = 1000000001; while(high-low > 1){ int mid = (high+low)/2; vector> dxy = {{-1,0},{0,1},{1,0},{0,-1}}; vector> dist(N,vector(M,1001001001)); if(A.at(0).at(0) < mid) dist.at(0).at(0) = 1; else dist.at(0).at(0) = 0; deque> Q; Q.push_back({0,0}); while(Q.size()){ auto [x,y] = Q.front(); Q.pop_front(); for(auto [dx,dy] : dxy){ int nx = dx+x,ny = dy+y; if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue; if(dist.at(nx).at(ny) != 1001001001) continue; if(A.at(nx).at(ny) >= mid) dist.at(nx).at(ny) = dist.at(x).at(y),Q.push_front({nx,ny}); else dist.at(nx).at(ny) = dist.at(x).at(y)+1,Q.push_back({nx,ny}); } } if(dist.at(N-1).at(M-1) > K) high = mid; else low = mid; } cout << low << endl; }