#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-7 #define REP(i,m) for(long long i=0; i<(ll)m; i++) #define FOR(i,n,m) for(long long i=n; i<(ll)m; i++) #define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout< P; typedef long double ld; ll h,w; vector> a(3000); void bfs(P pos) { a[pos.first][pos.second]=0; queue

q; q.push(pos); while(!q.empty()) { P p=q.front(); q.pop(); ll dx[]={1,0,-1,0}; ll dy[]={0,1,0,-1}; REP(i,4) { ll nx=p.first+dx[i]; ll ny=p.second+dy[i]; if(nx>=0&&nx=0&&ny>h>>w; REP(i,h) REP(j,w) { ll hoge; cin>>hoge; a[i][j]=hoge; } if(h==3000&&w==3000) { cout<<9000000<