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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define MAX_N (100005)
#define INF (1LL << 60)
const int MOD = (int)1e9 + 7;


signed main(){
	int H, W;
	cin >> H >> W;
	vector<string> A(H);
	for(int i=0; i<H; i++) cin >> A[i];

	set<int> st;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(A[i][j]=='#'){
				st.insert(i*H+j);
			}
		}
	}

	int ans=0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(A[i][j]=='.'){
				//DEBUG2(i,j);
				int p = i*H+j;
				auto it1 = st.lower_bound(p);
				auto it2 = prev(it1);
				int h1 = *it1/H, w1 = *it1%H;
				int h2 = *it2/H, w2 = *it2%H;
				//cout << abs(h1-i)+abs(w1-j) << endl;
				//cout << abs(h2-i)+abs(w2-j) << endl;
				int a1 = abs(h1-i)+abs(w1-j);
				int a2 = abs(h2-i)+abs(w2-j);
				ans = max(ans, min(a1,a2));
			}
		}
	}

	cout << ans << endl;

}