h,w = map(int,input().split())
s = [input() for i in range(h)]
ans = 0
from collections import deque
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':continue
        q = deque([(i,j)])
        reach = [[-1]*w for _ in range(h)]
        reach[i][j] = 0
        c = 0
        while q:
            x,y = q.popleft()
            for k,l in[[-1,0],[0,1],[1,0],[0,-1]]:
                if 0<=x+k<h and 0<=y+l<w:
                    if reach[x+k][y+l]<0 and s[x+k][y+l]=='.':
                        reach[x+k][y+l] = reach[x][y]+1
                        ans = max(ans,reach[x+k][y+l])
                        q.append((x+k,y+l))
            
print(ans)