from collections import deque



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

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

move = [(1,0), (0,1), (-1,0), (0,-1)]



queue = deque()

visited = [[-1] * w for _ in range(h)]

for row in range(h):

    for col in range(w):

        if a[row][col] == "#":

            visited[row][col] = 0

            queue.append((row, col, 0))

dist = 0

while queue:

    row, col, dist = queue.popleft()

    for drow, dcol in move:

        if a[row+drow:row+drow+1] and a[row+drow][col+dcol:col+dcol+1] and visited[row+drow][col+dcol] == -1 and a[row+drow][col+dcol] == ".":

            visited[row+drow][col+dcol] = dist + 1

            queue.append((row+drow, col+dcol, dist+1))





print(dist)

from collections import deque



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

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

move = [(1,0), (0,1), (-1,0), (0,-1)]



queue = deque()

visited = [[-1] * w for _ in range(h)]

for row in range(h):

    for col in range(w):

        if a[row][col] == "#":

            visited[row][col] = 0

            queue.append((row, col, 0))

dist = 0

while queue:

    row, col, dist = queue.popleft()

    for drow, dcol in move:

        if row+drow>=0 and row+drow<h and col+dcol>=0 and col+dcol<w and visited[row+drow][col+dcol] == -1 and a[row+drow][col+dcol] == ".":

            visited[row+drow][col+dcol] = dist + 1

            queue.append((row+drow, col+dcol, dist+1))





print(dist)

from collections import deque

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
queue = deque()
visited = [[-1] * w for _ in range(h)]
for row in range(h):
    for col in range(w):
        if a[row][col] == "#":
            visited[row][col] = 0
            queue.append((row, col, 0))
dist = 0
while queue:
    row, col, dist = queue.popleft()
    for drow, dcol in move:
        if (
            a[row + drow : row + drow + 1]
            and a[row + drow][col + dcol : col + dcol + 1]
            and visited[row + drow][col + dcol] == -1
            and a[row + drow][col + dcol] == "."
        ):
            visited[row + drow][col + dcol] = dist + 1
            queue.append((row + drow, col + dcol, dist + 1))
print(dist)

from collections import deque

h, w = list(map(int, input().split()))
a = [list(eval(input())) for _ in range(h)]
move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
queue = deque()
visited = [[-1] * w for _ in range(h)]
for row in range(h):
    for col in range(w):
        if a[row][col] == "#":
            visited[row][col] = 0
            queue.append((row, col, 0))
dist = 0
while queue:
    row, col, dist = queue.popleft()
    for drow, dcol in move:
        if (
            row + drow >= 0
            and row + drow < h
            and col + dcol >= 0
            and col + dcol < w
            and visited[row + drow][col + dcol] == -1
            and a[row + drow][col + dcol] == "."
        ):
            visited[row + drow][col + dcol] = dist + 1
            queue.append((row + drow, col + dcol, dist + 1))
print(dist)

-            a[row + drow : row + drow + 1] -            and a[row + drow][col + dcol : col + dcol + 1] +            row + drow >= 0 +            and row + drow < h +            and col + dcol >= 0 +            and col + dcol < w