from collections import deque

h,w = list(map(int,input().split()))

grid = [list(eval(input())) for _ in range(h)]

nxt = deque()

for i in range(h):

		for j in range(w):

			if grid[i][j] == "#":

				nxt.append((i,j,0))

a=0

while nxt:

	i,j,t = nxt.popleft()

	if t > a:

		a+=1

	for i,j in ((i-1,j),(i+1,j),(i,j-1),(i,j+1)):

		if (-1<i<h)&(-1<j<w) and grid[i][j] == ".":

				grid[i][j] = "#"

				nxt.append((i,j,t+1))

print(a)
from scipy.ndimage import distance_transform_cdt

h,w = list(map(int, input().split()))

grid = [[i=="." for i in eval(input())] for _ in range(h)]

print((distance_transform_cdt(grid, metric='taxicab').max()))



# reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html
from collections import deque

h, w = list(map(int, input().split()))
grid = [list(eval(input())) for _ in range(h)]
nxt = deque()
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            nxt.append((i, j, 0))
a = 0
while nxt:
    i, j, t = nxt.popleft()
    if t > a:
        a += 1
    for i, j in ((i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)):
        if (-1 < i < h) & (-1 < j < w) and grid[i][j] == ".":
            grid[i][j] = "#"
            nxt.append((i, j, t + 1))
print(a)

from scipy.ndimage import distance_transform_cdt

h, w = list(map(int, input().split()))
grid = [[i == "." for i in eval(input())] for _ in range(h)]
print((distance_transform_cdt(grid, metric="taxicab").max()))
# reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html

-from collections import deque +from scipy.ndimage import distance_transform_cdt -grid = [list(eval(input())) for _ in range(h)] -nxt = deque() -for i in range(h): -    for j in range(w): -        if grid[i][j] == "#": -            nxt.append((i, j, 0)) -a = 0 -while nxt: -    i, j, t = nxt.popleft() -    if t > a: -        a += 1 -    for i, j in ((i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)): -        if (-1 < i < h) & (-1 < j < w) and grid[i][j] == ".": -            grid[i][j] = "#" -            nxt.append((i, j, t + 1)) -print(a) +grid = [[i == "." for i in eval(input())] for _ in range(h)] +print((distance_transform_cdt(grid, metric="taxicab").max())) +# reference : https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.distance_transform_bf.html