#include using namespace std; #define int long long #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif char table[3003][3003]; int mp[3003][3003]; queue> q; const int INF = 1 << 30; signed main(){ int h,w; cin >> h >> w; for(int i = 0; i <= h+1; i++){ for(int j = 0; j <= w+1; j++){ if(i == 0 || j == 0 || i == h+1 || j == w+1){ q.push({i,j}); continue; } char c; scanf("%c",&c); table[i][j] = c; if(table[i][j] == '.'){ q.push({i,j}); } else mp[i][j] = INF; } } while(!q.empty()){ auto p = q.front(); q.pop(); for(int dx : {-1,0,1}){ for(int dy : {-1,0,1}){ int ny = p.first + dy; int nx = p.second + dx; if(ny < 0 || h+1 < ny || nx < 0 || w+1 < nx) continue; if(mp[ny][nx] == INF && !(dx == 0 && dy == 0)) q.push({ny,nx}); if((ny == 1 || ny == h || nx == 1 || nx == w) && table[ny][nx] == '#') mp[ny][nx] = 1; if(1 <= ny && ny <= h && 1 <= nx && nx <= w){ mp[p.first][p.second] = min(mp[p.first][p.second],mp[ny][nx]+1); } } } } int ans = 0; for(int i = 0; i <= h; i++){ for(int j = 0; j <= w; j++){ ans = max(ans,mp[i][j]); } } cout << ans << endl; return 0; }