#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; int dh[]={1,0,-1,0}; int dw[]={0,1,0,-1}; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m,k; cin>>n>>m>>k; VV A(n,V(m)); rep(i,n) rep(j,m) cin>>A[i][j]; ll ok=0,ng=1e9+1; while(ng-ok>1){ ll mid=(ok+ng)/2; VV B(n,V(m)),dis(n,V(m,-1)); rep(i,n) rep(j,m){ if(A[i][j]> que; que.push({0,0}); while(que.size()){ auto a=que.front(); que.pop(); int i=a.first,j=a.second; rep(k,4){ int ni=i+dh[k],nj=j+dw[k]; if(ni<0 || nj<0 || ni>=n || nj>=m) continue; if(B[ni][nj]){ if(dis[ni][nj]==-1){ dis[ni][nj]=dis[i][j]+1; que.push({ni,nj}); } else if(dis[ni][nj]>dis[i][j]+1){ dis[ni][nj]=dis[i][j]+1; que.push({ni,nj}); } } else{ if(dis[ni][nj]==-1){ dis[ni][nj]=dis[i][j]; que.push({ni,nj}); } else if(dis[ni][nj]>dis[i][j]){ dis[ni][nj]=dis[i][j]; que.push({ni,nj}); } } } } if(dis[n-1][m-1]<=k) ok=mid; else ng=mid; } cout<