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

from collections import deque

def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited = [[-1]*W for _ in range(H)]
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+i, x+j
            if not 0 <= new_y < H or not 0 <= new_x < W:
                continue
            if S[new_y][new_x] ==  "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x]+1
                q.append([new_y, new_x])
    return max(max(l) for l in visited)

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, bfs(i, j))
print (ans)