#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="< > P; int mat[3005][3005]; int main(){ int h,w; cin>>h>>w; fill(mat[0], mat[3005], INF); queue

que; char c[3005]; rep(i,h){ scanf("%s", c); rep(j,w){ if(c[j]=='.'){ mat[i][j] = 0; que.push(mp(0,mp(i,j))); } } } // insert out of map rep(i,h+2){ que.push(mp(0,mp(i-1, -1))); que.push(mp(0,mp(i-1, w)));} rep(i,w ){ que.push(mp(0,mp(-1, i))); que.push(mp(0,mp(h, i)));} while(!que.empty()){ const int di[] = {-1,1,0}, dj[]={0,-1,1}; P p = que.front(); que.pop(); int nl = p.first+1; int i = p.second.first, j = p.second.second; rep(ri, 3) rep(rj,3){ int ni = i+di[ri], nj = j+dj[rj]; if(ni<0 || ni>=h || nj<0 || nj>=w) continue; if(mat[ni][nj] > nl){ mat[ni][nj] = nl; que.push(mp(nl, mp(ni,nj))); } } } //rep(i,h){rep(j,w) printf("%2d", mat[i][j]); printf("\n");} int res=0; rep(i,h)rep(j,w) res = max(res, mat[i][j]); cout<