#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

int h , w , ans , p=0;
char grid[1005][1005];
queue <int> cx;
queue <int> cy;
int main(){
	
	cin>>h>>w;
	for (int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>grid[i][j];
			if (grid[i][j]=='#'){
				p++;
				cx.push(i);
				cy.push(j);
			}
		}
	}
	for (int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			if (grid[i][j]!='.' && grid[i][j]!='#'){
				grid[i][j] = '#';
			}
//			cout<<grid[i][j];
		}
//		cout<<endl;
	}
//	cout<<endl;
	int a , b , c;
	int dx[5] = {0,0,1,-1};
	int dy[5] = {1,-1,0,0};
	c = p;
	while (p!=h*w){
		ans++;
		c = cx.size();
		while(c!=0){
			a = cx.front();
			b = cy.front();
			for(int i=0;i<=3;i++){
				if (grid[a+dx[i]][b+dy[i]] == '.') {
					p++;
					grid[a+dx[i]][b+dy[i]] = '#';
					cx.push(a+dx[i]);
					cy.push(b+dy[i]);
				}
			}
			cx.pop();
			cy.pop();
			c--;
		}
			
//		for(int i=1;i<=h;i++){
//			for(int j=1;j<=w;j++){
//				cout<<grid[i][j];
//			}
//			cout<<endl;
//		}
//		cout<<endl;
	}

	cout<<ans<<endl;
}