H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
d=[(1,0),(0,1),(-1,0),(0,-1)]
ans=0
def search(n,m):
    X=[[0]*W for _ in range(H)]
    X[n][m]=1
    ans=-1
    que=[]
    que.append((n,m))
    while que:
        newque=[]
        for x,y in que:
            for dx,dy in d:
                if 0<=x+dx<H and 0<=y+dy<W and s[x+dx][y+dy]=="." and X[x+dx][y+dy]==0:
                    X[x+dx][y+dy]=1
                    newque.append((x+dx,y+dy))
        ans+=1
        que=newque
    return ans
        
for i in range(H):
    for j in range(W):
        if s[i][j]==".":
            ans=max(ans,search(i,j))
                
print(ans)