#include <bits/stdc++.h>
using namespace std;

int a,b,simp,lala,ans,n,m;
char arr[1005][1005];
queue <pair <int, int> > x;

bool cek(){
	bool y = 1;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(arr[i][j] == '.'){
				y = false;
			}
		}
	}	
	return y;
}

int main(){
	cin>>n>>m;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin>>arr[i][j];
			if(arr[i][j] == '#'){
				simp++;
				x.push(make_pair(i,j));
			}
		}
	}
	while(!cek()){
		ans++;
		lala = 0;
		while(simp>0){
			a = x.front().first;
			b = x.front().second;
			x.pop();
			if(arr[a-1][b] == '.' && a>1){
				arr[a-1][b] = '#';
				x.push(make_pair(a-1,b));
				lala++;
			}
			if(arr[a+1][b] == '.' && a<n){
				arr[a+1][b] = '#';
				x.push(make_pair(a+1,b));
				lala++;
			}
			if(arr[a][b-1] == '.' && b>1){
				arr[a][b-1] = '#';
				x.push(make_pair(a,b-1));
				lala++;
			}
			if(arr[a][b+1] == '.' && b<m){
				arr[a][b+1] = '#';
				x.push(make_pair(a,b+1));
				lala++;
			}
			simp--;
		}
		simp = lala;
	}
	cout<<ans<<endl;
}