//#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; using ld = long double; using P = pair; using vi = vector; using vd = vector; using vP = vector

; using vvi = vector>; using vvd = vector>; using vvP = vector>; using vvvi = vector>>; using vvvd = vector>>; using vvvP = vector>>; #if __has_include() #include using namespace atcoder; using mint = modint998244353; using Mint = modint1000000007; using vm = vector; using vM = vector; using vvm = vector>; using vvM = vector>; using vvvm = vector>>; using vvvM = vector>>; #endif #define rrep(i, n) for (ll i = (n)-1; (i) >= 0; --(i)) #define rep(i, n) for (ll i = 0; (i) < (n); ++(i)) #define reps(i, n) for (ll i = 1; (i) <= (n); ++(i)) #define Rep(i,a,b) for(ll i = (a); i <= (b); i++) #define all(a) (a).begin(),(a).end() const ll MOD = 998244353; #define Yes(b) ((b)?"Yes":"No") #define YES(b) ((b)?"YES":"NO") #define ft first #define sd second bool chmin(ll& a, ll b) { return a > b ? a = b, 1 : 0; } bool chmax(ll& a, ll b) { return a < b ? a = b, 1 : 0; } vi s90 = { 0, 1, 0, -1 }, c90 = { 1, 0, -1, 0 }; vi s45 = { 0, 1, 1, 1, 0, -1, -1, -1 }, c45 = { 1, 1, 0, -1, -1, -1, 0, 1 }; signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); ll N, M, K; cin >> N >> M >> K; vvi a(N, vi(M)); rep(i, N){ rep(k, M) cin >> a[i][k]; } if(K > N + M - 2){ cout << 1000000000 << endl; return 0; } ll L = 2, R = 1e9; auto solve = [&](ll m){ vvi dp(N, vi(M, 1e9)); if(a[0][0] >= m) dp[0][0] = 0; else dp[0][0] = 1; priority_queue> Q; Q.push({dp[0][0], 0}); while(!Q.empty()){ ll p = Q.top().sd, c = Q.top().ft; Q.pop(); rep(t, 4){ ll h = p / M + s90[t], w = p % M + c90[t]; if(h < 0 || w < 0 || h >= N || w >= M) continue; if(dp[h][w] == 1e9){ if(a[h][w] < m) dp[h][w] = dp[p/M][p%M] + 1; else dp[h][w] = dp[p/M][p%M]; Q.push({dp[h][w], h * M + w}); } } } return dp[N-1][M-1]; }; while(L <= R){ ll m = (L + R) / 2; if(solve(m) <= K) L = m + 1; else R = m - 1; } cout << R << endl; }