from collections import deque

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

A = 0

dp = [None] * H

mat = deque(maxlen=W*H)

for h in range(H):

    s = list(eval(input()))

    for w, x in zip(list(range(W)), s):

        if x == "#":

            mat.append((h, w, 0))

    dp[h] = s



while len(mat):

    h, w, cnt = mat.popleft()



    for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):

        if t and dp[h][w] == ".":

            mat.append((h, w, cnt+1))

            dp[h][w] = "#"



print(cnt)

from collections import deque

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

A = 0

dp = [None] * H

mat = deque()

for h in range(H):

    s = list(eval(input()))

    for w, x in zip(list(range(W)), s):

        if x == "#":

            mat.append((h, w, 0))

            s[w] = 1

        else:

            s[w] = 0

    dp[h] = s



while len(mat):

    h, w, cnt = mat.popleft()



    for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):

        if t and dp[h][w] == 0:

            mat.append((h, w, cnt+1))

            dp[h][w] = 1



print(cnt)

from collections import deque

H, W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque(maxlen=W * H)
for h in range(H):
    s = list(eval(input()))
    for w, x in zip(list(range(W)), s):
        if x == "#":
            mat.append((h, w, 0))
    dp[h] = s
while len(mat):
    h, w, cnt = mat.popleft()
    for t, h, w, cnt in (
        (h > 0, h - 1, w, cnt),
        (h < H - 1, h + 1, w, cnt),
        (w > 0, h, w - 1, cnt),
        (w < W - 1, h, w + 1, cnt),
    ):
        if t and dp[h][w] == ".":
            mat.append((h, w, cnt + 1))
            dp[h][w] = "#"
print(cnt)

from collections import deque

H, W = list(map(int, input().split()))
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
    s = list(eval(input()))
    for w, x in zip(list(range(W)), s):
        if x == "#":
            mat.append((h, w, 0))
            s[w] = 1
        else:
            s[w] = 0
    dp[h] = s
while len(mat):
    h, w, cnt = mat.popleft()
    for t, h, w, cnt in (
        (h > 0, h - 1, w, cnt),
        (h < H - 1, h + 1, w, cnt),
        (w > 0, h, w - 1, cnt),
        (w < W - 1, h, w + 1, cnt),
    ):
        if t and dp[h][w] == 0:
            mat.append((h, w, cnt + 1))
            dp[h][w] = 1
print(cnt)

-mat = deque(maxlen=W * H) +mat = deque() +            s[w] = 1 +        else: +            s[w] = 0 -        if t and dp[h][w] == ".": +        if t and dp[h][w] == 0: -            dp[h][w] = "#" +            dp[h][w] = 1