from collections import deque

import sys

input = sys.stdin.readline

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

a = [eval(input()) for i in range(h)]

nl = [[] for i in range(h)]

q = deque()

for i in range(h):

    for j in range(w):

        if a[i][j] == "#":

            nl[i].append(0)

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

        else:

            nl[i].append(-1)

while q:

    [s,t,cnt] = q.popleft()

    if s>0 and nl[s-1][t] == -1:

        q.append([s-1,t,cnt+1])

        nl[s-1][t] = cnt+1

    if s<h-1 and nl[s+1][t] == -1:

        q.append([s+1,t,cnt+1])

        nl[s+1][t] = cnt+1

    if t>0 and nl[s][t-1] == -1:

        q.append([s,t-1,cnt+1])

        nl[s][t-1] = cnt+1

    if t<w-1 and nl[s][t+1] == -1:

        q.append([s,t+1,cnt+1])

        nl[s][t+1] = cnt+1

ans = 0

for i in range(h):

    ans = max(ans,max(nl[i]))

print(ans)
from collections import deque

import sys

input = sys.stdin.readline

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

a = [list(input().rstrip()) for i in range(h)]

q = deque()

for i in range(h):

  for j in range(w):

    if a[i][j] == "#":

      a[i][j] = 0

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

    else:

      a[i][j] = -1

while q:

  s,t,cnt = q.popleft()

  for ns,nt in ((s+1,t),(s-1,t),(s,t+1),(s,t-1)):

    if 0<=ns<=h-1 and 0<=nt<=w-1 and a[ns][nt] == -1:

      q.append((ns,nt,cnt+1))

      a[ns][nt] = cnt+1

ans = 0

for i in range(h):

  for j in range(w):

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

print(ans)
from collections import deque
import sys

input = sys.stdin.readline
h, w = list(map(int, input().split(" ")))
a = [eval(input()) for i in range(h)]
nl = [[] for i in range(h)]
q = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            nl[i].append(0)
            q.append([i, j, 0])
        else:
            nl[i].append(-1)
while q:
    [s, t, cnt] = q.popleft()
    if s > 0 and nl[s - 1][t] == -1:
        q.append([s - 1, t, cnt + 1])
        nl[s - 1][t] = cnt + 1
    if s < h - 1 and nl[s + 1][t] == -1:
        q.append([s + 1, t, cnt + 1])
        nl[s + 1][t] = cnt + 1
    if t > 0 and nl[s][t - 1] == -1:
        q.append([s, t - 1, cnt + 1])
        nl[s][t - 1] = cnt + 1
    if t < w - 1 and nl[s][t + 1] == -1:
        q.append([s, t + 1, cnt + 1])
        nl[s][t + 1] = cnt + 1
ans = 0
for i in range(h):
    ans = max(ans, max(nl[i]))
print(ans)

from collections import deque
import sys

input = sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(input().rstrip()) for i in range(h)]
q = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            a[i][j] = 0
            q.append((i, j, 0))
        else:
            a[i][j] = -1
while q:
    s, t, cnt = q.popleft()
    for ns, nt in ((s + 1, t), (s - 1, t), (s, t + 1), (s, t - 1)):
        if 0 <= ns <= h - 1 and 0 <= nt <= w - 1 and a[ns][nt] == -1:
            q.append((ns, nt, cnt + 1))
            a[ns][nt] = cnt + 1
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, a[i][j])
print(ans)

-h, w = list(map(int, input().split(" "))) -a = [eval(input()) for i in range(h)] -nl = [[] for i in range(h)] +h, w = list(map(int, input().split())) +a = [list(input().rstrip()) for i in range(h)] -            nl[i].append(0) -            q.append([i, j, 0]) +            a[i][j] = 0 +            q.append((i, j, 0)) -            nl[i].append(-1) +            a[i][j] = -1 -    [s, t, cnt] = q.popleft() -    if s > 0 and nl[s - 1][t] == -1: -        q.append([s - 1, t, cnt + 1]) -        nl[s - 1][t] = cnt + 1 -    if s < h - 1 and nl[s + 1][t] == -1: -        q.append([s + 1, t, cnt + 1]) -        nl[s + 1][t] = cnt + 1 -    if t > 0 and nl[s][t - 1] == -1: -        q.append([s, t - 1, cnt + 1]) -        nl[s][t - 1] = cnt + 1 -    if t < w - 1 and nl[s][t + 1] == -1: -        q.append([s, t + 1, cnt + 1]) -        nl[s][t + 1] = cnt + 1 +    s, t, cnt = q.popleft() +    for ns, nt in ((s + 1, t), (s - 1, t), (s, t + 1), (s, t - 1)): +        if 0 <= ns <= h - 1 and 0 <= nt <= w - 1 and a[ns][nt] == -1: +            q.append((ns, nt, cnt + 1)) +            a[ns][nt] = cnt + 1 -    ans = max(ans, max(nl[i])) +    for j in range(w): +        ans = max(ans, a[i][j])