from collections import deque

def solve(s):
    queue = deque([])
    queue.appendleft(s)
    visited = [[-1 for _ in range(W)] for _ in range(H)]
    visited[s[0]][s[1]] = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + k
            if -1 < new_x and new_x < W and -1 < new_y and new_y < H and S[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
    return max(max(visited))

H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = -1
for i in range(H):
    for l in range(W):
        if S[i][l] != ".":
            continue
        ans = max(ans, solve([i, l]))
print(ans)