from collections import deque

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


def bfs(maze, visited, sh, sw, gh, gw, H, W):
    q = deque([(sh, sw)])
    visited[sh][sw] = 0

    while q:
        h, w = q.popleft()
        if h == gh and w == gw:
            return visited[gh][gw]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            nh = h + dh
            nw = w + dw
            if 0 <= nh < H and 0 <= nw < W:
                if maze[nh][nw] == "." and visited[nh][nw] == -1:
                    visited[nh][nw] = visited[h][w] + 1
                    q.append((nh, nw))

    return -1


ans = 0
for h in range(H):
    for w in range(W):
        for gh in range(H):
            for gw in range(W):
                if h == gh and w == gw:
                    continue
                visited = [[-1] * W for _ in range(H)]
                tmp = bfs(maze, visited, h, w, gh, gw, H, W)
                if tmp > ans:
                    ans = tmp
print(ans)
