#include<cstdio>
#include<algorithm>
using namespace std;
int n, m, D[1010][1010], dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }, head ,tail;
struct point {
	int x, y;
}Q[1010000];
char p[1010][1010];
void Put(int x, int y, int d) {
	if (x<1 || x>n || y<1 || y>m)return;
	if (D[x][y] <= d)return;
	D[x][y] = d;
	Q[++tail] = { x,y };
}
int main() {
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%s", p[i] + 1);
		for (j = 1; j <= m; j++) {
			D[i][j] = 1e9;
			if(p[i][j]=='#')Put(i, j, 0);
		}
	}
	while (head < tail) {
		point t = Q[++head];
		for (i = 0; i < 4; i++) {
			Put(t.x + dx[i], t.y + dy[i], D[t.x][t.y] + 1);
		}
	}
	printf("%d\n", D[Q[tail].x][Q[tail].y]);
}