def bfs(start, goal, maze, visited):
    queue = [start]
    visited[start[0]][start[1]] = True
    dist = {(start[0], start[1]): 0}
    while queue:
        y, x = queue.pop(0)
        if y == goal[0] and x == goal[1]:
            return dist[(y, x)]
        for i, j in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            x_, y_ = x + i, y + j
            if y_ >= 0 and y_ < h and x_ >= 0 and x_ < w and maze[y_][x_] == "." and not visited[y_][x_]:
                queue.append((y_, x_))
                visited[y_][x_] = True
                dist[y_, x_] = dist[y, x] + 1


h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
max_dist = 0
for sy in range(h):
    for sx in range(w):
        for gy in range(h):
            for gx in range(w):
                if maze[sy][sx] == "." and maze[gy][gx] == ".":
                    visited = [[False for _ in range(w)] for _ in range(h)]
                    max_dist = max(max_dist, bfs(
                        (sy, sx), (gy, gx), maze, visited))
print(max_dist)
