from collections import deque



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

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



bl = [[False] * W for _ in range(H)]

dq = deque()



for r in range(H):

    for c in range(W):

        if a[r][c] == '#':

            bl[r][c] = True

            dq.append((r, c, 0))





def in_range(r, c):

    return 0 <= r < H and 0 <= c < W





dr_s = (0, 0, -1, 1)

dc_s = (-1, 1, 0, 0)



while dq:

    r, c, d = dq.popleft()

    for dr, dc in zip(dr_s, dc_s):

        nr = r + dr

        nc = c + dc

        if not in_range(nr, nc): continue

        if bl[nr][nc]: continue

        bl[nr][nc] = True

        dq.append((nr, nc, d + 1))



print(d)

import sys



input = sys.stdin.readline



from collections import deque



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

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



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

dq = deque()



for r in range(H):

    for c in range(W):

        if a[r][c] == '#':

            dist[r][c] = 0

            dq.append((r, c))





def in_range(r, c):

    return 0 <= r < H and 0 <= c < W





dr_s = (0, 0, -1, 1)

dc_s = (-1, 1, 0, 0)



d = 0

while dq:

    r, c = dq.popleft()

    d = dist[r][c]

    for dr, dc in zip(dr_s, dc_s):

        nr = r + dr

        nc = c + dc

        if not in_range(nr, nc): continue

        if dist[nr][nc] != -1: continue

        dist[nr][nc] = d + 1

        dq.append((nr, nc))



print(d)

from collections import deque

H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
bl = [[False] * W for _ in range(H)]
dq = deque()
for r in range(H):
    for c in range(W):
        if a[r][c] == "#":
            bl[r][c] = True
            dq.append((r, c, 0))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
while dq:
    r, c, d = dq.popleft()
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc):
            continue
        if bl[nr][nc]:
            continue
        bl[nr][nc] = True
        dq.append((nr, nc, d + 1))
print(d)

import sys

input = sys.stdin.readline
from collections import deque

H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dist = [[-1] * W for _ in range(H)]
dq = deque()
for r in range(H):
    for c in range(W):
        if a[r][c] == "#":
            dist[r][c] = 0
            dq.append((r, c))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)
d = 0
while dq:
    r, c = dq.popleft()
    d = dist[r][c]
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc):
            continue
        if dist[nr][nc] != -1:
            continue
        dist[nr][nc] = d + 1
        dq.append((nr, nc))
print(d)

+import sys + +input = sys.stdin.readline -bl = [[False] * W for _ in range(H)] +dist = [[-1] * W for _ in range(H)] -            bl[r][c] = True -            dq.append((r, c, 0)) +            dist[r][c] = 0 +            dq.append((r, c)) +d = 0 -    r, c, d = dq.popleft() +    r, c = dq.popleft() +    d = dist[r][c] -        if bl[nr][nc]: +        if dist[nr][nc] != -1: -        bl[nr][nc] = True -        dq.append((nr, nc, d + 1)) +        dist[nr][nc] = d + 1 +        dq.append((nr, nc))