### BUGGY CODE ###

from collections import deque
H,W=map(int,input().split())

L=[]
Q=deque()
for i in range(H):
    a=list(input())
    for j in range(W):
        if a[j]==".":
            a[j]=10000
        else:
            a[j]=0
            Q.append([i,j,0])
    L.append(a)
    

#print(L)
#print(Q)
cnt=0
X=[1,-1,0,0]
Y=[0,0,1,-1]
for i in range(10**6+5):
    if len(Q)==0:
        break
    else:
        #print(Q)
        QZ=Q.popleft()
        for j in range(4):
            
            if (QZ[0]+1)<=(H-1) and j==0:
                #print(L[Q[0][0]+X[j]][Q[0][1]+Y[j]])
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=Q[0][2]+1
            if (QZ[0]-1)>=(0) and j==1:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=QZ[2]+1
            if (QZ[1]+1)<=(W-1) and j==2:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<Q[0][2]+1:
                        cnt=Q[0][2]+1
            if (QZ[1]-1)>=(0) and j==3:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=QZ[2]+1
        #print(L)
      

print(cnt)
#print(L)

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())

L=[]
Q=deque()
for i in range(H):
    a=list(input())
    for j in range(W):
        if a[j]==".":
            a[j]=10000
        else:
            a[j]=0
            Q.append([i,j,0])
    L.append(a)
    

#print(L)
#print(Q)
cnt=0
X=[1,-1,0,0]
Y=[0,0,1,-1]
for i in range(10**6+5):
    if len(Q)==0:
        break
    else:
        #print(Q)
        QZ=Q.popleft()
        for j in range(4):
            
            if (QZ[0]+1)<=(H-1) and j==0:
                #print(L[Q[0][0]+X[j]][Q[0][1]+Y[j]])
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=Q[0][2]+1
            if (QZ[0]-1)>=(0) and j==1:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=QZ[2]+1
            if (QZ[1]+1)<=(W-1) and j==2:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<Q[0][2]+1:
                        cnt=Q[0][2]+1
            if (QZ[1]-1)>=(0) and j==3:
                if L[QZ[0]+X[j]][QZ[1]+Y[j]]>(QZ[2]+1):
                    L[QZ[0]+X[j]][QZ[1]+Y[j]]=(QZ[2]+1)
                    Q.append([QZ[0]+X[j],QZ[1]+Y[j],QZ[2]+1])
                    if cnt<QZ[2]+1:
                        cnt=QZ[2]+1
        #print(L)
      

print(cnt)
#print(L)