H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
inf=float("inf")
data=[[inf]*W for i in range(H)]
start=[0,0]
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            start=[i,j]
d=[[1,0],[0,1],[-1,0],[0,-1]]
que=[[start[0],start[1]]]
data[start[0]][start[1]]=0
count=1
while que:
    h=[]
    for x,y in que:
        for dx,dy in d:
            nx,ny=x+dx,y+dy
            if 0<=nx<H and 0<=ny<W and S[nx][ny]=="." and data[nx][ny]==inf:
                h.append([nx,ny])
                data[nx][ny]=count
    que=h
    count+=1
z=[0,0]
num=0
for i in range(H):
    for j in range(W):
        if data[i][j]!=inf and data[i][j]>num:
            num=data[i][j]
            z=[i,j]
data=[[inf]*W for i in range(H)]
que=[z]
data[z[0]][z[1]]=0
count=1
while que:
    h=[]
    for x,y in que:
        for dx,dy in d:
            nx,ny=x+dx,y+dy
            if 0<=nx<H and 0<=ny<W and S[nx][ny]=="." and data[nx][ny]==inf:
                h.append([nx,ny])
                data[nx][ny]=count
    que=h
    count+=1
ans=0
for i in range(H):
    for j in range(W):
        if data[i][j]==inf:
            continue
        ans=max(ans,data[i][j])
print(ans)