
H, W = list(map(int, input().split()))

maze = []
for _ in range(H):
    maze.append(list(input()))

def dfs(i, j, path):
    global ans
    if i == end[0] and j == end[1]:
        # print(path)
        ans = min(ans, path)
        return 

    for dx, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        x = i + dx
        y = j + dj
        if 0 <= x < H and 0 <= y < W and maze[x][y] == "." :
            if (x, y) not in seen:
                seen.add((x, y))
                dfs(x, y, path+1)
                seen.discard((x, y))   
    return

res = []
for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                if maze[i][j] == "." and maze[k][j] == ".":
                    ans = float("inf")
                    seen = set()
                    seen.add((i, j))
                    end = (k, l)
                    dfs(i, j, 0)
                    if ans != float("inf"):
                        res.append(ans)
                    # res = max(res, ans if ans != float("inf") else 0)

print(max(res))
