from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    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 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())

sy, sx, gy, gx = 3, 1, 1, 5

maze = ["#"*(W+2)]
for i in range(H):
    tmp = "#"
    tmp += input()
    tmp += "#"
    maze.append(tmp)
maze.append("#"*(W+2))
    
#for i in range(H+2):
#    print(maze[i])

max_bfs = 0
for sy in range(1, H+2):
    for sx in range(1, W+2):
        for gy in range(1, H+2):
            for gx in range(1, W+2):
                if maze[sy][sx] == "." and maze[gy][gx] == ".":
                    visited = [[-1]*(W+2) for j in range(H+2)]
                    tmp_bfs = bfs(maze, visited, sy, sx, gy, gx)
                    if tmp_bfs > max_bfs:
                        max_bfs = tmp_bfs
                
print(max_bfs)
