#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k; cin >> h >> w >> k; if(k > h + w){ cout << 1'000'000'000 << '\n'; return 0; } k = min(k, h + w); vector dp(h, vector(w, vector(k + 1, -1'000'000'003))); vector A(h, vector(w)); cin >> A; priority_queue> pq; dp[0][0][0] = A[0][0]; pq.emplace(A[0][0], 0, 0, 0); if(k >= 1){ dp[0][0][1] = 1'000'000'000; pq.emplace(1'000'000'000, 0, 0, 1); } vector> dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; while(!pq.empty()){ auto [d, y, x, s] = pq.top(); pq.pop(); if(d < dp[y][x][s]) continue; for(auto [ny, nx] : dir){ ny += y, nx += x; if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if(min(d, A[ny][nx]) > dp[ny][nx][s]){ dp[ny][nx][s] = min(d, A[ny][nx]); pq.emplace(dp[ny][nx][s], ny, nx, s); } if(s + 1 <= k && d > dp[ny][nx][s + 1]){ dp[ny][nx][s + 1] = d; pq.emplace(d, ny, nx, s + 1); } } } cout << *max_element(dp[h - 1][w - 1].begin(), dp[h - 1][w - 1].end()) << '\n'; }