#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[1001][1001],x,y,ans=0;
	char b[1001][1001],c;
	
	priority_queue <pair<int,int> > xy;
	
	cin>>x>>y;
	
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			cin>>c;
			b[i][j]=c;
			if(c=='#') {
				a[i][j] = 0;
				xy.push(make_pair(i,j));
			}
			else a[i][j] = -1;
		}
	}
	while(!xy.empty()){
		int xx = xy.top().first;
		int yy = xy.top().second;
		xy.pop();
		for(int i=0;i<y;i++){
			if(a[xx][i]==-1) a[xx][i] = abs(yy-i);
			else a[xx][i] = min(a[xx][i],abs(yy-i)); 
		}
		for(int i =0;i<x;i++){
			if(a[i][yy]==-1) a[i][yy] = abs(xx-i);
			else a[i][yy] = min(a[i][yy],abs(xx-i));
		}
	}
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			if(a[i][j]==-1){
				a[i][j] = x + y -1;
			}
			if(i>0) a[i][j] = min(a[i][j],a[i-1][j]+1);
			if(i<x-1) a[i][j] = min(a[i][j],a[i+1][j]+1);
			if(j>0) a[i][j] = min(a[i][j],a[i][j-1]+1);
			if(j<y-1) a[i][j] = min(a[i][j],a[i][j+1]+1);
			ans = max(ans,a[i][j]);
			//cout<<a[i][j];
		}
		//cout<<'\n';
	}
	cout<<ans<<'\n';
}