from collections import deque

H,W = list(map(int,input().split()))

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

que = deque([])

for i in range(H):

    for j in range(W):

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

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

tot = 0

while que:

    i,j,cnt = que.popleft()

    if j+1<W and A[i][j+1]==".":

        A[i][j+1]="#"

        que.append((i,j+1,cnt+1))

        tot = cnt+1

    if j-1>-1 and A[i][j-1]==".":

        A[i][j-1]="#"

        que.append((i,j-1,cnt+1))

        tot = cnt+1

    if i+1<H and A[i+1][j]==".":

        A[i+1][j]="#"

        que.append((i+1,j,cnt+1))

        tot = cnt+1

    if i-1>-1 and A[i-1][j]==".":

        A[i-1][j]="#"

        que.append((i-1,j,cnt+1))

        tot = cnt+1

print(tot)
from collections import deque

H,W = list(map(int,input().split()))

A = [input().strip() for _ in range(H)]

B = [[-1 for j in range(W)] for i in range(H)]

que = deque([])

for i in range(H):

    for j in range(W):

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

            B[i][j] = 0

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

bmax = 0

while que:

    i,j,d = que.popleft()

    bmax = max(bmax,d)

    if j+1<W and B[i][j+1]<0:

        B[i][j+1] = d+1

        que.append((i,j+1,d+1))

    if i-1>=0 and B[i-1][j]<0:

        B[i-1][j] = d+1

        que.append((i-1,j,d+1))

    if j-1>=0 and B[i][j-1]<0:

        B[i][j-1] = d+1

        que.append((i,j-1,d+1))

    if i+1<H and B[i+1][j]<0:

        B[i+1][j] = d+1

        que.append((i+1,j,d+1))

print(bmax)
from collections import deque

H, W = list(map(int, input().split()))
A = [list(input().strip()) for _ in range(H)]
que = deque([])
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            que.append((i, j, 0))
tot = 0
while que:
    i, j, cnt = que.popleft()
    if j + 1 < W and A[i][j + 1] == ".":
        A[i][j + 1] = "#"
        que.append((i, j + 1, cnt + 1))
        tot = cnt + 1
    if j - 1 > -1 and A[i][j - 1] == ".":
        A[i][j - 1] = "#"
        que.append((i, j - 1, cnt + 1))
        tot = cnt + 1
    if i + 1 < H and A[i + 1][j] == ".":
        A[i + 1][j] = "#"
        que.append((i + 1, j, cnt + 1))
        tot = cnt + 1
    if i - 1 > -1 and A[i - 1][j] == ".":
        A[i - 1][j] = "#"
        que.append((i - 1, j, cnt + 1))
        tot = cnt + 1
print(tot)

from collections import deque

H, W = list(map(int, input().split()))
A = [input().strip() for _ in range(H)]
B = [[-1 for j in range(W)] for i in range(H)]
que = deque([])
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            B[i][j] = 0
            que.append((i, j, 0))
bmax = 0
while que:
    i, j, d = que.popleft()
    bmax = max(bmax, d)
    if j + 1 < W and B[i][j + 1] < 0:
        B[i][j + 1] = d + 1
        que.append((i, j + 1, d + 1))
    if i - 1 >= 0 and B[i - 1][j] < 0:
        B[i - 1][j] = d + 1
        que.append((i - 1, j, d + 1))
    if j - 1 >= 0 and B[i][j - 1] < 0:
        B[i][j - 1] = d + 1
        que.append((i, j - 1, d + 1))
    if i + 1 < H and B[i + 1][j] < 0:
        B[i + 1][j] = d + 1
        que.append((i + 1, j, d + 1))
print(bmax)

-A = [list(input().strip()) for _ in range(H)] +A = [input().strip() for _ in range(H)] +B = [[-1 for j in range(W)] for i in range(H)] +            B[i][j] = 0 -tot = 0 +bmax = 0 -    i, j, cnt = que.popleft() -    if j + 1 < W and A[i][j + 1] == ".": -        A[i][j + 1] = "#" -        que.append((i, j + 1, cnt + 1)) -        tot = cnt + 1 -    if j - 1 > -1 and A[i][j - 1] == ".": -        A[i][j - 1] = "#" -        que.append((i, j - 1, cnt + 1)) -        tot = cnt + 1 -    if i + 1 < H and A[i + 1][j] == ".": -        A[i + 1][j] = "#" -        que.append((i + 1, j, cnt + 1)) -        tot = cnt + 1 -    if i - 1 > -1 and A[i - 1][j] == ".": -        A[i - 1][j] = "#" -        que.append((i - 1, j, cnt + 1)) -        tot = cnt + 1 -print(tot) +    i, j, d = que.popleft() +    bmax = max(bmax, d) +    if j + 1 < W and B[i][j + 1] < 0: +        B[i][j + 1] = d + 1 +        que.append((i, j + 1, d + 1)) +    if i - 1 >= 0 and B[i - 1][j] < 0: +        B[i - 1][j] = d + 1 +        que.append((i - 1, j, d + 1)) +    if j - 1 >= 0 and B[i][j - 1] < 0: +        B[i][j - 1] = d + 1 +        que.append((i, j - 1, d + 1)) +    if i + 1 < H and B[i + 1][j] < 0: +        B[i + 1][j] = d + 1 +        que.append((i + 1, j, d + 1)) +print(bmax)