#include <bits/stdc++.h>
using namespace std;
int arr[1005][1005];
queue <pair<int,int> > q;
int langkah[1005][1005];
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x,y; cin >> x >> y;
	char c;
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++){
			cin >> c;
			langkah[i][j]=-1;
			if(c=='#'){
				arr[i][j]=1;
				q.push({i,j});
				langkah[i][j]=0;
			}
			else arr[i][j]=0;
		}
		while(!q.empty()){
			pair<int,int> qq;
			qq=q.front();
			int a = qq.first;
			int b = qq.second;
			q.pop();
			//cout << a <<' '<<b <<' '<<langkah[a][b]<<" LOL "<<endl;
			if(b<y && langkah[a][b+1]==-1){
				q.push({a,b+1}); 
				langkah[a][b+1]=langkah[a][b]+1;
			}
			if(b>1 && langkah[a][b-1]==-1){
				q.push({a,b-1});
				langkah[a][b-1]=langkah[a][b]+1;
			}
			if(a<x && langkah[a+1][b]==-1){
				q.push({a+1,b});
				langkah[a+1][b]=langkah[a][b]+1;
			}
			if(a>1 && langkah[a-1][b]==-1){
				q.push({a-1,b});
				langkah[a-1][b]=langkah[a][b]+1;
			}
		}
		int maxi = -100000;
		for(int i=1;i<=x;i++)
			for(int j=1;j<=y;j++){
				maxi=max(maxi,langkah[i][j]);
			}
		cout << maxi << endl;
}