import sys

from collections import deque



stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)



ri = lambda: int(rs())

rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers

rs = lambda: stdin.readline().rstrip()  # ignores trailing space



H, W = rl()

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

answer = 0

que = deque()

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

for i in range(H):

    for j in range(W):

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

            data[i][j] = 0

            que.append((j, i))

while que:

    dx = [1, 0, -1, 0]

    dy = [0, 1, 0, -1]

    p = que.popleft()

    for i in range(4):

        nx = p[0] + dx[i]

        ny = p[1] + dy[i]

        if 0 <= ny <= H-1 and 0 <= nx <= W-1:

            if data[ny][nx] == -1:

                data[ny][nx] = data[p[1]][p[0]] + 1

                que.append((nx, ny))

answer = max([max(z) for z in data])

print(answer)

# 54

import sys

import numpy as np



stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)



ri = lambda: int(rs())

rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers

rs = lambda: stdin.readline().rstrip()  # ignores trailing space



H, W = rl()

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



INF = 10 ** 5

B = np.array([[0 if x == '#' else INF for x in row] for row in A])



for i in range(1, H):

    B[i] = np.minimum(B[i], B[i-1] + 1)

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

    B[i] = np.minimum(B[i], B[i+1] + 1)

for j in range(1, W):

    B[:, j] = np.minimum(B[:, j], B[:, j-1] + 1)

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

    B[:, j] = np.minimum(B[:, j], B[:, j+1] + 1)



print((B.max()))



import sys
from collections import deque

stdin = sys.stdin
sys.setrecursionlimit(10**7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
answer = 0
que = deque()
data = [[-1] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            data[i][j] = 0
            que.append((j, i))
while que:
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    p = que.popleft()
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        if 0 <= ny <= H - 1 and 0 <= nx <= W - 1:
            if data[ny][nx] == -1:
                data[ny][nx] = data[p[1]][p[0]] + 1
                que.append((nx, ny))
answer = max([max(z) for z in data])
print(answer)
# 54

import sys
import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10**7)
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space
H, W = rl()
A = [list(rs()) for _ in range(H)]
INF = 10**5
B = np.array([[0 if x == "#" else INF for x in row] for row in A])
for i in range(1, H):
    B[i] = np.minimum(B[i], B[i - 1] + 1)
for i in range(H - 2, -1, -1):
    B[i] = np.minimum(B[i], B[i + 1] + 1)
for j in range(1, W):
    B[:, j] = np.minimum(B[:, j], B[:, j - 1] + 1)
for j in range(W - 2, -1, -1):
    B[:, j] = np.minimum(B[:, j], B[:, j + 1] + 1)
print((B.max()))

-from collections import deque +import numpy as np -answer = 0 -que = deque() -data = [[-1] * W for _ in range(H)] -for i in range(H): -    for j in range(W): -        if A[i][j] == "#": -            data[i][j] = 0 -            que.append((j, i)) -while que: -    dx = [1, 0, -1, 0] -    dy = [0, 1, 0, -1] -    p = que.popleft() -    for i in range(4): -        nx = p[0] + dx[i] -        ny = p[1] + dy[i] -        if 0 <= ny <= H - 1 and 0 <= nx <= W - 1: -            if data[ny][nx] == -1: -                data[ny][nx] = data[p[1]][p[0]] + 1 -                que.append((nx, ny)) -answer = max([max(z) for z in data]) -print(answer) -# 54 +INF = 10**5 +B = np.array([[0 if x == "#" else INF for x in row] for row in A]) +for i in range(1, H): +    B[i] = np.minimum(B[i], B[i - 1] + 1) +for i in range(H - 2, -1, -1): +    B[i] = np.minimum(B[i], B[i + 1] + 1) +for j in range(1, W): +    B[:, j] = np.minimum(B[:, j], B[:, j - 1] + 1) +for j in range(W - 2, -1, -1): +    B[:, j] = np.minimum(B[:, j], B[:, j + 1] + 1) +print((B.max()))