### BUGGY CODE ###

H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)

w=[]
cnt=[[10**7 for _ in range(W)]for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            for y,x in w:
                val=abs(y-i)+abs(x-j)
                cnt[y][x]=min(cnt[y][x],val)
            w=[]
        else:
            w.append([i,j])
w=[]
for i in range(H):
    for j in range(W):
        y=i
        if i%2==0:
            x=j
        else:
            x=W-1-j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
w=[]
for i in range(H):
    for j in range(W):
        y=i
        x=W-1-j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])

for i in range(H):
    for j in range(W):
        y=i
        if i%2==0:
            x=W-1-j
        else:
            x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])

for j in range(W):
    for i in range(H):
        y=i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        if j%2==0:
            y=i
        else:
            y=H-1-i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        y=H-1-i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        if j%2==0:
            y=H-1-i
        else:
            y=i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
ans=0
for i in range(H):
    for j in range(W):
        if A[i][j]==".":
            ans=max(ans,cnt[i][j])

print(ans)

### FIXED CODE ###

from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)