from collections import deque



H, W = [int(i) for i in input().split()]

A = [list(eval(input())) for _ in range(H)]



Q = deque((i, j, 0) for i in range(H) for j in range(W) if A[i][j] == "#")



ans = 0

while Q:

    i, j, dist = Q.popleft()

    ans = max(ans, dist)

    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:

        ni, nj = i + di, j + dj

        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":

            A[ni][nj] = "#"

            Q.append((ni, nj, dist + 1))



print(ans)

from collections import deque



H, W = [int(i) for i in input().split()]

A = [list(eval(input())) for _ in range(H)]



Q = deque()

for i in range(H):

    for j in range(W):

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

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



ma = 0

while Q:

    i, j, dist = Q.popleft()

    ma = max(ma, dist)

    for ni, nj in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:

        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":

            A[ni][nj] = "#"

            Q.append((ni, nj, dist + 1))



print(ma)
from collections import deque

H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
Q = deque((i, j, 0) for i in range(H) for j in range(W) if A[i][j] == "#")
ans = 0
while Q:
    i, j, dist = Q.popleft()
    ans = max(ans, dist)
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))
print(ans)

from collections import deque

H, W = [int(i) for i in input().split()]
A = [list(eval(input())) for _ in range(H)]
Q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            Q.append((i, j, 0))
ma = 0
while Q:
    i, j, dist = Q.popleft()
    ma = max(ma, dist)
    for ni, nj in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))
print(ma)

-Q = deque((i, j, 0) for i in range(H) for j in range(W) if A[i][j] == "#") -ans = 0 +Q = deque() +for i in range(H): +    for j in range(W): +        if A[i][j] == "#": +            Q.append((i, j, 0)) +ma = 0 -    ans = max(ans, dist) -    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]: -        ni, nj = i + di, j + dj +    ma = max(ma, dist) +    for ni, nj in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]: -print(ans) +print(ma)