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

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



#dp[i][j]=最も近い黒マスまでの最小マンハッタン距離

INF=10**9

dp = [[INF] * W for _ in range(H)]



#右

for i in range(H):

    c = INF

    for j in range(W):

        if A[i][j] == '#': c = 0

        elif j>=1: c = dp[i][j-1] + 1

        dp[i][j] = min(dp[i][j], c)



#下

for j in range(W):

    c = INF

    for i in range(H):

        if A[i][j] == '#': c = 0

        elif i>=1: c = dp[i-1][j] + 1

        dp[i][j] = min(dp[i][j], c)



#左

for i in range(H):

    c = INF

    for j in range(W-1,-1,-1):

        if A[i][j] == '#': c = 0

        elif j<W-1: c = dp[i][j+1] + 1

        dp[i][j] = min(dp[i][j], c)



#上

for j in range(W):

    c = INF

    for i in range(H-1,-1,-1):

        if A[i][j] == '#': c = 0

        elif i<H-1: c = dp[i+1][j] + 1

        dp[i][j] = min(dp[i][j], c)



ans=0

for i in range(H):

    for j in range(W):

        ans = max(ans, dp[i][j])

print(ans)

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)

import sys

from collections import deque

def main(H, W, A):

    dist = [[-1] * W for _ in range(H)]

    q = deque()

    for i in range(H):

        for j in range(W):

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

                dist[i][j] = 0

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



    ans = 0

    while q:

        i, j, d = q.popleft()

        ans = max(ans, d)

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

            if not (0 <= ni < H and 0 <= nj < W): continue

            if dist[ni][nj] >= 0: continue

            dist[ni][nj] = d + 1

            q.append((ni, nj, d + 1))

    print(ans)



if __name__ == '__main__':

    input = sys.stdin.readline

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

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

    main(H, W, A)

H, W = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
# dp[i][j]=最も近い黒マスまでの最小マンハッタン距離
INF = 10**9
dp = [[INF] * W for _ in range(H)]
# 右
for i in range(H):
    c = INF
    for j in range(W):
        if A[i][j] == "#":
            c = 0
        elif j >= 1:
            c = dp[i][j - 1] + 1
        dp[i][j] = min(dp[i][j], c)
# 下
for j in range(W):
    c = INF
    for i in range(H):
        if A[i][j] == "#":
            c = 0
        elif i >= 1:
            c = dp[i - 1][j] + 1
        dp[i][j] = min(dp[i][j], c)
# 左
for i in range(H):
    c = INF
    for j in range(W - 1, -1, -1):
        if A[i][j] == "#":
            c = 0
        elif j < W - 1:
            c = dp[i][j + 1] + 1
        dp[i][j] = min(dp[i][j], c)
# 上
for j in range(W):
    c = INF
    for i in range(H - 1, -1, -1):
        if A[i][j] == "#":
            c = 0
        elif i < H - 1:
            c = dp[i + 1][j] + 1
        dp[i][j] = min(dp[i][j], c)
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dp[i][j])
print(ans)

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
from collections import deque


def main(H, W, A):
    dist = [[-1] * W for _ in range(H)]
    q = deque()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                dist[i][j] = 0
                q.append((i, j, 0))
    ans = 0
    while q:
        i, j, d = q.popleft()
        ans = max(ans, d)
        for ni, nj in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
            if not (0 <= ni < H and 0 <= nj < W):
                continue
            if dist[ni][nj] >= 0:
                continue
            dist[ni][nj] = d + 1
            q.append((ni, nj, d + 1))
    print(ans)


if __name__ == "__main__":
    input = sys.stdin.readline
    H, W = list(map(int, input().split()))
    A = [input().rstrip() for _ in range(H)]
    main(H, W, A)

-H, W = list(map(int, input().split())) -A = [list(eval(input())) for _ in range(H)] -# dp[i][j]=最も近い黒マスまでの最小マンハッタン距離 -INF = 10**9 -dp = [[INF] * W for _ in range(H)] -# 右 -for i in range(H): -    c = INF -    for j in range(W): -        if A[i][j] == "#": -            c = 0 -        elif j >= 1: -            c = dp[i][j - 1] + 1 -        dp[i][j] = min(dp[i][j], c) -# 下 -for j in range(W): -    c = INF +# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) +import sys +from collections import deque + + +def main(H, W, A): +    dist = [[-1] * W for _ in range(H)] +    q = deque() -        if A[i][j] == "#": -            c = 0 -        elif i >= 1: -            c = dp[i - 1][j] + 1 -        dp[i][j] = min(dp[i][j], c) -# 左 -for i in range(H): -    c = INF -    for j in range(W - 1, -1, -1): -        if A[i][j] == "#": -            c = 0 -        elif j < W - 1: -            c = dp[i][j + 1] + 1 -        dp[i][j] = min(dp[i][j], c) -# 上 -for j in range(W): -    c = INF -    for i in range(H - 1, -1, -1): -        if A[i][j] == "#": -            c = 0 -        elif i < H - 1: -            c = dp[i + 1][j] + 1 -        dp[i][j] = min(dp[i][j], c) -ans = 0 -for i in range(H): -    for j in range(W): -        ans = max(ans, dp[i][j]) -print(ans) +        for j in range(W): +            if A[i][j] == "#": +                dist[i][j] = 0 +                q.append((i, j, 0)) +    ans = 0 +    while q: +        i, j, d = q.popleft() +        ans = max(ans, d) +        for ni, nj in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]: +            if not (0 <= ni < H and 0 <= nj < W): +                continue +            if dist[ni][nj] >= 0: +                continue +            dist[ni][nj] = d + 1 +            q.append((ni, nj, d + 1)) +    print(ans) + + +if __name__ == "__main__": +    input = sys.stdin.readline +    H, W = list(map(int, input().split())) +    A = [input().rstrip() for _ in range(H)] +    main(H, W, A)