from collections import deque

H,W=map(int,input().split())
Map=[input() for j in range(H)]

def bps(si,sj):
    distance=[[-1]*W for j in range(H)]
    distance[si][sj]=0
    deq=deque([[si,sj]])
    fdis=0
    while deq:
        i,j=deq.popleft()
        for dir_i,dir_j in [(-1,0),(1,0),(0,-1),(0,1)]:
            if 0<=i+dir_i<H and 0<=j+dir_j<W and distance[i+dir_i][j+dir_j]==-1 and Map[i+dir_i][j+dir_j]==".":
                distance[i+dir_i][j+dir_j]=fdis=distance[i][j]+1
                deq.append([i+dir_i,j+dir_j])
    return fdis

bestMapDistance=0
for i in range(H):
    for j in range(W):
        bestMapDistance=max(bps(i,j),bestMapDistance)

print(bestMapDistance)





