h,w=map(int,input().split())
s=[list(input())for i in range(h)]
d=0
for i in range(h):
    if d:
        break
    for j in range(w):
        if s[i][j]==".":
            p=[i,j]
            d=1
            break
q=[p]
t=[[1]*w for j in range(h)]
t[p[0]][p[1]]=1
while q:
    c=[]
    for i,j in q:
        a=[1,-1,0,0]
        b=[0,0,1,-1]
        for d in range(4):
            if 0<=i+a[d]<h and 0<=j+b[d]<w:
                if s[i+a[d]][j+b[d]]==".":
                    if t[i+a[d]][j+b[d]]:
                        t[i+a[d]][j+b[d]]=0
                        c.append([i+a[d],j+b[d]])
    if len(c)==0:
        p=[q[0][0],q[0][1]]
        break
    else:
        q=c[::]
q=[p]
t=[[1]*w for j in range(h)]
t[p[0]][p[1]]=0
g=0
while q:
    c=[]
    for i,j in q:
        a=[1,-1,0,0]
        b=[0,0,1,-1]
        for d in range(4):
            if 0<=i+a[d]<h and 0<=j+b[d]<w:
                if s[i+a[d]][j+b[d]]==".":
                    if t[i+a[d]][j+b[d]]:
                        t[i+a[d]][j+b[d]]=0
                        c.append([i+a[d],j+b[d]])
    if len(c)==0:
        break
    else:
        g+=1
        q=c[::]
print(g)