#darker　and darker

from collections import deque

d=deque()

e=deque()

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

field=[0 for i in range(h+2)]

field[0]=[True for i in range(w+2)]

distance=0

for i in range(h):

    s=eval(input())

    a=[False for i in range(w+2)]

    a[0]=True

    for j in range(w):

        if s[j]=="#":

            a[j+1]=True

            d.append((i+1,j+1))

    a[w+1]=True

    field[i+1]=a

field[h+1]=[True for i in range(w+2)]

while d:

    while d:

        some=d.popleft()

        index1,index2=some[0],some[1]

        if field[index1-1][index2]==False:

                field[index1-1][index2]=True

                e.append((index1-1,index2))

        if field[index1+1][index2]==False:

                field[index1+1][index2]=True

                e.append((index1+1,index2))

        if field[index1][index2+1]==False:

                field[index1][index2+1]=True

                e.append((index1,index2+1))

        if  field[index1][index2-1]==False:

                field[index1][index2-1]=True

                e.append((index1,index2-1))

    distance+=1

    d=e

    e=deque()

print((distance-1))

    

# Review problem

from collections import deque

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

D = [list(eval(input())) for i in range(H)]



visited = [[False for i in range(W)] for j in range(H)]

dis = [[0 for i in range(W)] for j in range(H)]



black = deque()

dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]

for i in range(H):

    for j in range(W):

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

            visited[i][j] = True

            black.append((i, j))



while black:

    x, y = black.popleft()

    for dx, dy in dif:

        if 0 <= dx+x < H and 0 <= dy+y < W and visited[dx+x][dy+y] == False:

            visited[dx+x][dy+y] = True

            dis[dx+x][dy+y] = dis[x][y]+1

            black.append((dx+x, dy+y))

ans = 0

for i in range(H):

    for j in range(W):

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

print(ans)
# darker　and darker
from collections import deque

d = deque()
e = deque()
h, w = list(map(int, input().split()))
field = [0 for i in range(h + 2)]
field[0] = [True for i in range(w + 2)]
distance = 0
for i in range(h):
    s = eval(input())
    a = [False for i in range(w + 2)]
    a[0] = True
    for j in range(w):
        if s[j] == "#":
            a[j + 1] = True
            d.append((i + 1, j + 1))
    a[w + 1] = True
    field[i + 1] = a
field[h + 1] = [True for i in range(w + 2)]
while d:
    while d:
        some = d.popleft()
        index1, index2 = some[0], some[1]
        if field[index1 - 1][index2] == False:
            field[index1 - 1][index2] = True
            e.append((index1 - 1, index2))
        if field[index1 + 1][index2] == False:
            field[index1 + 1][index2] = True
            e.append((index1 + 1, index2))
        if field[index1][index2 + 1] == False:
            field[index1][index2 + 1] = True
            e.append((index1, index2 + 1))
        if field[index1][index2 - 1] == False:
            field[index1][index2 - 1] = True
            e.append((index1, index2 - 1))
    distance += 1
    d = e
    e = deque()
print((distance - 1))

# Review problem
from collections import deque

H, W = list(map(int, input().split()))
D = [list(eval(input())) for i in range(H)]
visited = [[False for i in range(W)] for j in range(H)]
dis = [[0 for i in range(W)] for j in range(H)]
black = deque()
dif = [(-1, 0), (1, 0), (0, 1), (0, -1)]
for i in range(H):
    for j in range(W):
        if D[i][j] == "#":
            visited[i][j] = True
            black.append((i, j))
while black:
    x, y = black.popleft()
    for dx, dy in dif:
        if 0 <= dx + x < H and 0 <= dy + y < W and visited[dx + x][dy + y] == False:
            visited[dx + x][dy + y] = True
            dis[dx + x][dy + y] = dis[x][y] + 1
            black.append((dx + x, dy + y))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dis[i][j])
print(ans)

-# darker　and darker +# Review problem -d = deque() -e = deque() -h, w = list(map(int, input().split())) -field = [0 for i in range(h + 2)] -field[0] = [True for i in range(w + 2)] -distance = 0 -for i in range(h): -    s = eval(input()) -    a = [False for i in range(w + 2)] -    a[0] = True -    for j in range(w): -        if s[j] == "#": -            a[j + 1] = True -            d.append((i + 1, j + 1)) -    a[w + 1] = True -    field[i + 1] = a -field[h + 1] = [True for i in range(w + 2)] -while d: -    while d: -        some = d.popleft() -        index1, index2 = some[0], some[1] -        if field[index1 - 1][index2] == False: -            field[index1 - 1][index2] = True -            e.append((index1 - 1, index2)) -        if field[index1 + 1][index2] == False: -            field[index1 + 1][index2] = True -            e.append((index1 + 1, index2)) -        if field[index1][index2 + 1] == False: -            field[index1][index2 + 1] = True -            e.append((index1, index2 + 1)) -        if field[index1][index2 - 1] == False: -            field[index1][index2 - 1] = True -            e.append((index1, index2 - 1)) -    distance += 1 -    d = e -    e = deque() -print((distance - 1)) +H, W = list(map(int, input().split())) +D = [list(eval(input())) for i in range(H)] +visited = [[False for i in range(W)] for j in range(H)] +dis = [[0 for i in range(W)] for j in range(H)] +black = deque() +dif = [(-1, 0), (1, 0), (0, 1), (0, -1)] +for i in range(H): +    for j in range(W): +        if D[i][j] == "#": +            visited[i][j] = True +            black.append((i, j)) +while black: +    x, y = black.popleft() +    for dx, dy in dif: +        if 0 <= dx + x < H and 0 <= dy + y < W and visited[dx + x][dy + y] == False: +            visited[dx + x][dy + y] = True +            dis[dx + x][dy + y] = dis[x][y] + 1 +            black.append((dx + x, dy + y)) +ans = 0 +for i in range(H): +    for j in range(W): +        ans = max(ans, dis[i][j]) +print(ans)