#include <cstdio>
#include <queue>
#include <utility>
typedef std::pair<int,int> P;
typedef std::pair<int,P> node;
const int way[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
char s[1005][1005];
int main() {
	int h,w;scanf("%d%d",&h,&w);
	int ans=0;std::queue<node> q;
	for(register int i=1;i<=h;++i) {
		scanf("%s",s[i]+1);
		for(register int j=1;j<=w;++j) {
			if(s[i][j]=='#') q.push(node(0,P(i,j)));
		}
	}
	while(q.size()) {
		node cur=q.front();q.pop();
		for(register int i=0;i<4;++i) {
			int x=cur.second.first+way[i][0];
			int y=cur.second.second+way[i][1];
			if(1<=x&&x<=h&&1<=y&&y<=w&&s[x][y]=='.') {
				s[x][y]='#';q.push(node(cur.first+1,P(x,y)));
			}
		}
		ans=std::max(ans,cur.first);
	}
	printf("%d\n",ans);
	return 0;
}
