#include using namespace std; const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; int main() { int N, M, K; cin >> N >> M >> K; vector A(N, vector(M, 0)); for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cin >> A[i][j]; auto isok = [&](int v) -> bool { vector P(N, vector(M, N*M+1)); P[0][0] = 0; deque> deq; deq.push_front({0, 0}); while(!deq.empty()) { auto [x, y] = deq.front(); deq.pop_front(); for(int dir = 0; dir < 4; dir++) { int nx(x + dx[dir]), ny(y + dy[dir]); if(0 <= nx && nx < N && 0 <= ny && ny < M) { if(A[x][y] < v) { if(P[x][y]+1 < P[nx][ny]) { P[nx][ny] = P[x][y]+1; deq.push_back({nx, ny}); } }else { if(P[x][y] < P[nx][ny]) { P[nx][ny] = P[x][y]; deq.push_front({nx, ny}); } } } } } return (P[N-1][M-1] <= K); }; int ok(1), ng(1000000001); while(1 < ng-ok) { int mid((ok+ng)/2); if(isok(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }