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

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



#上下左右のマスを黒くしていく

#BFS

from collections import deque

def bfs():

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

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

    log=[[0]*w for i in range(h)]



    que=deque()

    for i in range(h):

        for j in range(w):

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

                que.append((i,j))



    while que:

        #queの先頭を取り出す

        p=que.popleft()

        for i in range(4):

            nx=p[0]+dx[i]

            ny=p[1]+dy[i]



            if not(0<=nx<h and 0<=ny<w):continue

            if a[nx][ny]=='#':continue

            que.append((nx,ny))

            log[nx][ny]=log[p[0]][p[1]]+1

            a[nx][ny]='#'



    return log



G=bfs()

ans=0

for i in range(h):

    for j in range(w):

        if ans<G[i][j]:

            ans=G[i][j]

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

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



#上下左右のマスを黒くしていく

#BFS

from collections import deque

def bfs():

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

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

    log=[[-1]*w for i in range(h)]



    que=deque()

    for i in range(h):

        for j in range(w):

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

                que.append((i,j))

                log[i][j]=0



    while que:

        #queの先頭を取り出す

        p=que.popleft()

        for i in range(4):

            nx=p[0]+dx[i]

            ny=p[1]+dy[i]



            if not(0<=nx<h and 0<=ny<w):continue

            if log[nx][ny]!=-1:continue

            que.append((nx,ny))

            log[nx][ny]=log[p[0]][p[1]]+1



    return log



G=bfs()

ans=0

for i in range(h):

    for j in range(w):

        if ans<G[i][j]:

            ans=G[i][j]

print(ans)

#print(*G,sep='\n')
h, w = list(map(int, input().split()))
a = [list(eval(input())) for i in range(h)]
# 上下左右のマスを黒くしていく
# BFS
from collections import deque


def bfs():
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    log = [[0] * w for i in range(h)]
    que = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                que.append((i, j))
    while que:
        # queの先頭を取り出す
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if not (0 <= nx < h and 0 <= ny < w):
                continue
            if a[nx][ny] == "#":
                continue
            que.append((nx, ny))
            log[nx][ny] = log[p[0]][p[1]] + 1
            a[nx][ny] = "#"
    return log


G = bfs()
ans = 0
for i in range(h):
    for j in range(w):
        if ans < G[i][j]:
            ans = G[i][j]
print(ans)

h, w = list(map(int, input().split()))
a = [list(eval(input())) for i in range(h)]
# 上下左右のマスを黒くしていく
# BFS
from collections import deque


def bfs():
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    log = [[-1] * w for i in range(h)]
    que = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                que.append((i, j))
                log[i][j] = 0
    while que:
        # queの先頭を取り出す
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if not (0 <= nx < h and 0 <= ny < w):
                continue
            if log[nx][ny] != -1:
                continue
            que.append((nx, ny))
            log[nx][ny] = log[p[0]][p[1]] + 1
    return log


G = bfs()
ans = 0
for i in range(h):
    for j in range(w):
        if ans < G[i][j]:
            ans = G[i][j]
print(ans)
# print(*G,sep='\n')

-    log = [[0] * w for i in range(h)] +    log = [[-1] * w for i in range(h)] +                log[i][j] = 0 -            if a[nx][ny] == "#": +            if log[nx][ny] != -1: -            a[nx][ny] = "#" +# print(*G,sep='\n')