import sys
from heapq import *
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

H,W=nm()

INF=10**18
def dijkstra(start,edge):
    d=[[INF]*W for i in range(H)]
    d[start[0]][start[1]]=0
    q=[(0,start[0],start[1])]
    while(len(q)!=0):
        ci,i,j=heappop(q)
        #if(d[start[0]][start[1]]<ci):
        #    continue 
        for p in edge[i][j]:
            if(d[p[0]][p[1]]>d[i][j]+1):
                d[p[0]][p[1]]=d[i][j]+1
                heappush(q,(d[p[0]][p[1]],p[0],p[1]))
    return d

E=[[[] for _ in range(W)] for _ in range(H)] 
S=[] 

for i in range(H):
    tmp=ns()
    S.append(tmp)
    

for i in range(H):
    for j in range(W):
        if( j+1<=W-1 and S[i][j+1]=='.'):
            E[i][j].append((i,j+1))
        if( i+1<=H-1 and S[i+1][j]=='.'):
            E[i][j].append((i+1,j))
        if(S[i][j-1]=='.' and 0<=j-1):
            E[i][j].append((i,j-1))
        if(S[i-1][j]=='.' and 0<=i-1):
            E[i][j].append((i-1,j))



ans=0

d=[[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        d=dijkstra((i,j),E)
        for k in range(H):
            for l in  range(W):
                if(ans<d[k][l] and d[k][l]<10**18):
                    ans=d[k][l]
                    
print(ans)