#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; template using V=vector; template using VV=V>; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } Graph G; vector dijkstra(int s){ int n=G.size(); vector dist(n,INF); dist[s]=0; priority_queue,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m,k; cin>>n>>m>>k; VV A(n,V(m)); rep(i,n) rep(j,m) cin>>A[i][j]; int ok=0,ng=1e9+1; while(ng-ok>1){ int mid=(ok+ng)/2; G.resize(n*m); rep(i,n) rep(j,m){ int t=i*m+j; if(A[i][j]0) G[t-1].push_back(Edge(t,1)); if(j0) G[t-m].push_back(Edge(t,1)); if(i0) G[t-1].push_back(Edge(t,0)); if(j0) G[t-m].push_back(Edge(t,0)); if(i