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

#define ff first
#define ss second
#define pii pair<int,int>

int dist,n,m;
char arr[1005][1005];
bool visit[1005][1005];
vector<pii> v;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++){
			cin >> arr[i][j];
			if(arr[i][j] == '#') v.push_back({i,j});
		}
	queue<pair<int,pii> > q;
	for(pii i : v){
		q.push({0,i});
		visit[i.ff][i.ss] = 1;
	}
	while(!q.empty()){
		dist = q.front().ff;
		pii now = q.front().ss;
		q.pop();
		visit[now.ff][now.ss] = 1;
		if(now.ff > 0){
			if(!visit[now.ff-1][now.ss])
				q.push({dist+1,{now.ff-1,now.ss}});
		}
		if(now.ff < n-1){
			if(!visit[now.ff+1][now.ss])
				q.push({dist+1,{now.ff+1,now.ss}});
		}
		if(now.ss > 0){
			if(!visit[now.ff][now.ss-1])
				q.push({dist+1,{now.ff,now.ss-1}});
		}
		if(now.ss < m-1){
			if(!visit[now.ff][now.ss+1])
				q.push({dist+1,{now.ff,now.ss+1}});
		}
	}
	cout << dist << '\n';
	return 0;
}