from collections import deque



h,w = list(map(int,input().split()))

A = []

for i in range(h):

    A += list(eval(input()))



queue = deque([])

Distance = [-1]*(h*w)



for i in range(h):

    for j in range(w):

        if A[i*w+j]=='#':

            queue.append([i,j])

            Distance[i*w+j] = 0



ans = 0



while queue:

    x,y = queue.popleft()

    d = Distance[x*w+y]

    if x!=0 and Distance[(x-1)*w+y] == -1:

            queue.append([x-1,y])

            ans = Distance[(x-1)*w+y] = d+1

    if x!=h-1 and Distance[(x+1)*w+y] == -1:

            queue.append([x+1,y])

            ans = Distance[(x+1)*w+y] = d+1

    if y!=0 and Distance[x*w+y-1] == -1:

            queue.append([x,y-1])

            ans = Distance[x*w+y-1] = d+1

    if y!=w-1 and Distance[x*w+y+1] == -1:

            queue.append([x,y+1])

            ans = Distance[x*w+y+1] = d+1



print(ans)
from collections import deque



import sys

input = sys.stdin.readline



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

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



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

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

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



queue = deque()



for x in range(H):

    for y in range(W):

        if A[x][y] == '#':

            z = x * W + y

            queue.append(z)

            dist[z] = 0



while queue:

    z = queue.popleft()

    x, y = divmod(z, W)

    for k in range(4):

        nx = x + dx[k]

        ny = y + dy[k]

        if not (0 <= nx < H and 0 <= ny < W):

            continue

        nz = nx * W + ny

        if dist[nz] != -1:

            continue

        dist[nz] = dist[z] + 1

        queue.append(nz)



print((max(dist)))
from collections import deque

h, w = list(map(int, input().split()))
A = []
for i in range(h):
    A += list(eval(input()))
queue = deque([])
Distance = [-1] * (h * w)
for i in range(h):
    for j in range(w):
        if A[i * w + j] == "#":
            queue.append([i, j])
            Distance[i * w + j] = 0
ans = 0
while queue:
    x, y = queue.popleft()
    d = Distance[x * w + y]
    if x != 0 and Distance[(x - 1) * w + y] == -1:
        queue.append([x - 1, y])
        ans = Distance[(x - 1) * w + y] = d + 1
    if x != h - 1 and Distance[(x + 1) * w + y] == -1:
        queue.append([x + 1, y])
        ans = Distance[(x + 1) * w + y] = d + 1
    if y != 0 and Distance[x * w + y - 1] == -1:
        queue.append([x, y - 1])
        ans = Distance[x * w + y - 1] = d + 1
    if y != w - 1 and Distance[x * w + y + 1] == -1:
        queue.append([x, y + 1])
        ans = Distance[x * w + y + 1] = d + 1
print(ans)

from collections import deque
import sys

input = sys.stdin.readline
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = list(map(int, input().split()))
A = [eval(input()) for _ in range(H)]
dist = [-1 for _ in range(H * W)]
queue = deque()
for x in range(H):
    for y in range(W):
        if A[x][y] == "#":
            z = x * W + y
            queue.append(z)
            dist[z] = 0
while queue:
    z = queue.popleft()
    x, y = divmod(z, W)
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        nz = nx * W + ny
        if dist[nz] != -1:
            continue
        dist[nz] = dist[z] + 1
        queue.append(nz)
print((max(dist)))

+import sys -h, w = list(map(int, input().split())) -A = [] -for i in range(h): -    A += list(eval(input())) -queue = deque([]) -Distance = [-1] * (h * w) -for i in range(h): -    for j in range(w): -        if A[i * w + j] == "#": -            queue.append([i, j]) -            Distance[i * w + j] = 0 -ans = 0 +input = sys.stdin.readline +dx = [1, 0, -1, 0] +dy = [0, 1, 0, -1] +H, W = list(map(int, input().split())) +A = [eval(input()) for _ in range(H)] +dist = [-1 for _ in range(H * W)] +queue = deque() +for x in range(H): +    for y in range(W): +        if A[x][y] == "#": +            z = x * W + y +            queue.append(z) +            dist[z] = 0 -    x, y = queue.popleft() -    d = Distance[x * w + y] -    if x != 0 and Distance[(x - 1) * w + y] == -1: -        queue.append([x - 1, y]) -        ans = Distance[(x - 1) * w + y] = d + 1 -    if x != h - 1 and Distance[(x + 1) * w + y] == -1: -        queue.append([x + 1, y]) -        ans = Distance[(x + 1) * w + y] = d + 1 -    if y != 0 and Distance[x * w + y - 1] == -1: -        queue.append([x, y - 1]) -        ans = Distance[x * w + y - 1] = d + 1 -    if y != w - 1 and Distance[x * w + y + 1] == -1: -        queue.append([x, y + 1]) -        ans = Distance[x * w + y + 1] = d + 1 -print(ans) +    z = queue.popleft() +    x, y = divmod(z, W) +    for k in range(4): +        nx = x + dx[k] +        ny = y + dy[k] +        if not (0 <= nx < H and 0 <= ny < W): +            continue +        nz = nx * W + ny +        if dist[nz] != -1: +            continue +        dist[nz] = dist[z] + 1 +        queue.append(nz) +print((max(dist)))