#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "< P; int h,w; int mp[3535][3535]; int mn[3535][3535]; int dx[] = {1,0,-1,0,1,1,-1,-1}; int dy[] = {0,1,0,-1,1,-1,-1,1}; const int NICO = 830252521; int main(){ REP(i,3535)REP(j,3535)mn[i][j] = NICO; scanf("%d%d",&h,&w); REP(i,h){ char s[3531]; scanf("%s",s); REP(j,w){ mp[i][j] = s[j]=='.'; } } queue Q; REP(i,h)REP(j,w){ if(mp[i][j])continue; if(i==0 || j==0 || i==h-1 || j==w-1){ mn[i][j] = 1; Q.push(pii(i,j)); }else{ REP(d,8){ if(mp[i+dy[d]][j+dx[d]]){ mn[i][j] = 1; Q.push(pii(i,j)); break; } } } } int ans = 0; while(!Q.empty()){ pii P = Q.front(); Q.pop(); int y = P.first; int x = P.second; CHMAX(ans,mn[y][x]); REP(d,8){ int ny = y+dy[d]; int nx = x+dx[d]; if(ny<0 || nx<0 || ny>=h || nx>=w)continue; if(mp[ny][nx])continue; if(mn[ny][nx] != NICO)continue; mn[ny][nx] = mn[y][x] + 1; Q.push(pii(ny,nx)); } } printf("%d\n",ans); return 0; }