from collections import deque

H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append([c=='.' for c in input()])

d=[[-1 for j in range(W)] for i in range(H)]
f=False
for i in range(H):
    if f:
        break
    for j in range(W):
        if S[i][j]:
            si,sj=i,j
            f=True
            break
# print((si,sj))
q=deque()
q.append((si,sj));d[si][sj]=0
while q:
    ui,uj=q.popleft()    
    for vi,vj in [(ui-1,uj),(ui+1,uj),(ui,uj-1),(ui,uj+1)]:
        # print(q)     
        if 0<=vi<H and 0<=vj<W and d[vi][vj]==-1 and S[vi][vj] :
            q.append((vi,vj));d[vi][vj]=d[ui][uj]+1
for i in range(H):
    for j in range(W):
        if d[si][sj]<d[i][j]:
            si,sj=i,j
'''
for Si in S:
    print(Si)
for di in d:
    print(di)
'''
d=[[-1 for j in range(W)] for i in range(H)]
# print(si,sj)
q.append((si,sj));d[si][sj]=0
while q:
    ui,uj=q.popleft()    
    for vi,vj in [(ui-1,uj),(ui+1,uj),(ui,uj-1),(ui,uj+1)]:
        # print(q)     
        if 0<=vi<H and 0<=vj<W and d[vi][vj]==-1 and S[vi][vj] :
            q.append((vi,vj));d[vi][vj]=d[ui][uj]+1
for i in range(H):
    for j in range(W):
        if d[si][sj]<d[i][j]:
            si,sj=i,j
'''
for Si in S:
    print(Si)
for di in d:
    print(di)
'''
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,d[i][j])

print(ans)