from collections import deque

def bfs(maze, sy, sx, gy, gx, H, W):
    """
    maze>>迷路
    visited>>探索済み
    sy, sx>>スタート地点
    gy, gx>>ゴール地点
    """
    queue = deque([[sy, sx]])
    visited = [[-1]*W for _ in range(H)]
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k

            if new_y < 0 or H -1 < new_y or new_x < 0 or W -1 < new_x:
                continue
            elif maze[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])


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

answer_list = []
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] == '#':
            break
        for gy in range(H):
            for gx in range(W):
                if maze[gy][gx] == '#':
                    break
                answer_list.append(bfs(maze, sy, sx, gy, gx, H, W))

print(max(answer_list))