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

int n,m,x,a,b,c;
bool arr[1005][1005];
char y;
queue < pair < pair <int,int> , int> > q;

int main(){
	memset(arr, -1, sizeof(arr));
	cin>>n>>m;
	x = n*m;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			cin>>y;
			if(y == '#'){ 
				arr[i][j] = 1;
				q.push(make_pair(make_pair(i,j),0));
			}
		}
	}
	while(x>1){
		a = q.front().first.first;
		b = q.front().first.second;
		c = q.front().second;
		q.pop();
		x--;
		if(a>1 && arr[a-1][b] == 0){
			q.push(make_pair(make_pair(a-1,b),c+1));
			arr[a-1][b] = 1;
		}
		if(a<n && arr[a+1][b] == 0){
			q.push(make_pair(make_pair(a+1,b),c+1));
			arr[a+1][b] = 1;
		}
		if(b>1 && arr[a][b-1] == 0){
			q.push(make_pair(make_pair(a,b-1),c+1));
			arr[a][b-1] = 1;
		}
		if(b<m && arr[a][b+1] == 0){
			q.push(make_pair(make_pair(a,b+1),c+1));
			arr[a][b+1] = 1;
		}
	}
	cout<<q.front().second<<endl;
	q.pop();
}