#define IN(x,s,g) ((x) >= (s) && (x) < (g)) #define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h))) #include #include #define REP(i,n) for(int i=0; i<(int)(n); i++) #include inline int getInt(){ int s; scanf("%d", &s); return s; } #include using namespace std; int d[3000][3000]; char g[3000][3010]; int main(){ const int h = getInt(); const int w = getInt(); REP(i,h) scanf("%s", g[i]); memset(d, -1, sizeof(d)); queue > q; REP(i,h) REP(j,w) if(g[i][j] == '.') { d[i][j] = 0; q.push(make_pair(j, i)); } REP(i,h) { if(d[i][0] == -1) { d[i][0] = 1; q.push(make_pair(0, i)); } if(d[i][w-1] == -1) { d[i][w-1] = 1; q.push(make_pair(w-1, i)); } } REP(i,w) { if(d[0][i] == -1) { d[0][i] = 1; q.push(make_pair(i, 0)); } if(d[h-1][i] == -1) { d[h-1][i] = 1; q.push(make_pair(i, h-1)); } } while (q.size()){ const auto data = q.front (); q.pop(); const int x = data.first; const int y = data.second; REP(i,3) REP(j,3) { const int xx = x + i - 1; const int yy = y + j - 1; if(ISIN(xx, yy, w, h) && d[yy][xx] == -1){ q.push(make_pair(xx, yy)); d[yy][xx] = d[y][x] + 1; } } } // REP(i,h) { REP(j,w) printf("%02d ", d[i][j]); puts(""); } int ans = 0; REP(i,h) REP(j,w) ans = max(ans, d[i][j]); printf("%d\n", ans); return 0; }