H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

graph = [[float('inf')]*H*W for _ in range(H*W)]
nv = [(-1, 0), (1, 0), (0, -1), (0, 1)]

for h in range(H):
    for w in range(W):
        if S[h][w]=='.':
            for nx, ny in nv:
                if H <= h+nx or h+nx < 0 or W <= w+ny or w+ny < 0:
                    continue
                if S[h+nx][w+ny]=='.':
                    graph[W*h+w][W*(h+nx)+(w+ny)] = 1

for k in range(H*W):
    for i in range(H*W):
        for j in range(H*W):
            graph[i][i]=0
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
ans = 0
for i in range(H*W-1):
    for j in range(i+1, H*W):
        if graph[i][j] != float('inf'):
            ans = max(ans, graph[i][j])
print(ans)