#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define repr(i,a,n) for(int i = n-1;i >= a;i--)
#define ALL(v) v.begin(), v.end()
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}
/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/
bool is_visited[1001][1001] = {false};
char cell[1001][1001];
ll ans[1001][1001] = {};
ll h,w,memo = 0;
ll cnt = -1;
/*
void bfs(ll y,ll x,ll d){
	//cout << y << " " << x << " " << d << endl;
	is_visited[y][x] = true;
	
	
	if(cell[y][x] == '#'){
		d = 0;
	}
	
	ans[y][x] = d;
	
	if(y+1 < h){
		if(!is_visited[y+1][x] || ans[y+1][x] > d+1){
			bfs(y+1,x,d+1);
		}
	}
	
	if(y-1 >= 0){
		if(!is_visited[y-1][x] || ans[y-1][x] > d+1){
			bfs(y-1,x,d+1);
		}
	}
	
	if(x+1 < w ){
		if(!is_visited[y][x+1] || ans[y][x+1] > d+1){
			bfs(y,x+1,d+1);
		}
	}
	
	if(x-1 >= 0){
		if(!is_visited[y][x-1] || ans[y][x-1] > d+1){
			bfs(y,x-1,d+1);
		}
	}
	
	
	return;
}
*/

signed main(){
	
	bool flag = true;
	cin >> h >> w;
	
	rep(i,0,h)rep(j,0,w){
		cin >> cell[i][j];
	}
	
	ll memo = LINF;
	ll cnt = 0;
	
	
	rep(i,0,h){
		rep(j,0,w){
			ans[i][j] = memo;
		}
	}
	
	
	rep(i,0,h){
		memo = LINF;
		rep(j,0,w){
			memo++;
			if(cell[i][j] == '#'){
				memo = 0;
			}
			
			ans[i][j] = min(ans[max((ll)i-1,(ll)0)][j]+1,min(ans[min((ll)i+1,h-1)][j]+1,min(ans[i][min((ll)j+1,w-1)]+1,min(ans[i][max((ll)j-1,(ll)0)]+1,min(memo,ans[i][j])))));
		}
	}
	
	
	repr(i,0,h){
		memo = LINF;
		rep(j,0,w){
			memo++;
			if(cell[i][j] == '#'){
				memo = 0;
			}
			
			ans[i][j] = min(ans[max((ll)i-1,(ll)0)][j]+1,min(ans[min((ll)i+1,h-1)][j]+1,min(ans[i][min((ll)j+1,w-1)]+1,min(ans[i][max((ll)j-1,(ll)0)]+1,min(memo,ans[i][j])))));
		}
	}
	
	
	
	rep(i,0,h){
		memo = LINF;
		repr(j,0,w){
			memo++;
			if(cell[i][j] == '#'){
				memo = 0;
			}
			
			ans[i][j] = min(ans[max((ll)i-1,(ll)0)][j]+1,min(ans[min((ll)i+1,h-1)][j]+1,min(ans[i][min((ll)j+1,w-1)]+1,min(ans[i][max((ll)j-1,(ll)0)]+1,min(memo,ans[i][j])))));
		}
	}
	
	
	repr(i,0,h){
		memo = LINF;
		repr(j,0,w){
			memo++;
			if(cell[i][j] == '#'){
				memo = 0;
			}
			
			ans[i][j] = min(ans[max((ll)i-1,(ll)0)][j]+1,min(ans[min((ll)i+1,h-1)][j]+1,min(ans[i][min((ll)j+1,w-1)]+1,min(ans[i][max((ll)j-1,(ll)0)]+1,min(memo,ans[i][j])))));
		}
	}
	
	
	
	rep(i,0,h){
		rep(j,0,w){
			cnt = max(ans[i][j],cnt);
			//cout << ans[i][j];
		}
		//cout << endl;
	}
	
	cout << cnt << endl;
	
	
	return 0;
}


Measured memory_bytes: 9088