from collections import deque

def bfs(sx, sy, gx, gy):
    dist = [[-1]*W for _ in range(H)]
    dist[sx][sy] = 0
    q = deque([(sx, sy)])
    
    while q:
        cx, cy = q.popleft()
        
        for nx, ny in [(cx-1, cy), (cx+1, cy), (cx, cy-1), (cx, cy+1)]:
            if not (0<=nx<H and 0<=ny<W):
                continue
            
            if S[nx][ny]=='.' and dist[nx][ny]==-1:
                dist[nx][ny] = dist[cx][cy]+1
                q.append((nx, ny))
    
    return dist[gx][gy]

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
ans = -10**18

for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                if S[i][j]!='#' and S[k][l]!='#':
                    ans = max(ans, bfs(i, j, k, l))

print(ans)