from collections import deque

def mbfs(S,H,W):

    dxy=[[1,0],[0,1],[-1,0],[0,-1]]

    while(len(d)!=0):

        h,w,x=d.popleft()

        for t,y in dxy:

            if(0<=h+t<=H-1 and 0<=w+y<=W-1 and S[h+t][w+y]!='#'):

                S[h+t][w+y]='#'

                d.append([h+t,w+y,x+1])

    return x

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

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

d=deque()

for i in range(H):

    for j in range(W):

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

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

print((mbfs(A,H,W)))
from collections import deque

def mbfs(S,H,W,d):

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

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

    while(len(d)!=0):

        h=d[0][0]

        w=d[0][1]

        x=d[0][2]

        d.popleft()

        for di in range(4):

            nh=h+dx[di]

            nw=w+dy[di]

            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):

                continue

            if(S[nh][nw]=='#'):

                continue

            S[nh][nw]='#'

            d.append([nh,nw,x+1])

    return x

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

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

d=deque()

for i in range(H):

    for j in range(W):

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

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

print((mbfs(A,H,W,d)))

from collections import deque


def mbfs(S, H, W):
    dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    while len(d) != 0:
        h, w, x = d.popleft()
        for t, y in dxy:
            if 0 <= h + t <= H - 1 and 0 <= w + y <= W - 1 and S[h + t][w + y] != "#":
                S[h + t][w + y] = "#"
                d.append([h + t, w + y, x + 1])
    return x


H, W = list(map(int, input().split()))
A = [list(eval(input())) for i in range(H)]
d = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            d.append([i, j, 0])
print((mbfs(A, H, W)))

from collections import deque


def mbfs(S, H, W, d):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    while len(d) != 0:
        h = d[0][0]
        w = d[0][1]
        x = d[0][2]
        d.popleft()
        for di in range(4):
            nh = h + dx[di]
            nw = w + dy[di]
            if nh > H - 1 or nh < 0 or nw > W - 1 or nw < 0:
                continue
            if S[nh][nw] == "#":
                continue
            S[nh][nw] = "#"
            d.append([nh, nw, x + 1])
    return x


H, W = list(map(int, input().split()))
A = [list(eval(input())) for i in range(H)]
d = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            d.append([i, j, 0])
print((mbfs(A, H, W, d)))

-def mbfs(S, H, W): -    dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]] +def mbfs(S, H, W, d): +    dx = [1, 0, -1, 0] +    dy = [0, 1, 0, -1] -        h, w, x = d.popleft() -        for t, y in dxy: -            if 0 <= h + t <= H - 1 and 0 <= w + y <= W - 1 and S[h + t][w + y] != "#": -                S[h + t][w + y] = "#" -                d.append([h + t, w + y, x + 1]) +        h = d[0][0] +        w = d[0][1] +        x = d[0][2] +        d.popleft() +        for di in range(4): +            nh = h + dx[di] +            nw = w + dy[di] +            if nh > H - 1 or nh < 0 or nw > W - 1 or nw < 0: +                continue +            if S[nh][nw] == "#": +                continue +            S[nh][nw] = "#" +            d.append([nh, nw, x + 1]) -print((mbfs(A, H, W))) +print((mbfs(A, H, W, d)))