import numpy as np
from scipy.sparse.csgraph import floyd_warshall
h, w = map(int, input().split())
S = [input() for _ in range(h)]

INF = 100

maze = np.zeros((h*w, h*w))
for i in range(h*w-1):
    for j in range(i+1, h*w):
        i_h, i_w = divmod(i, w)
        j_h, j_w = divmod(j, w)

        if (S[i_h][i_w] == "." and
            S[j_h][j_w] == "." and
            abs(i_h-j_h) + abs(i_w-j_w) == 1):
            maze[i][j] = 1
            maze[j][i] = 1
        else:
            maze[i][j] = INF
            maze[j][i] = INF

# print(maze)

# for i in range(h*w):
#     for j in range(h*w):
#         for k in range(h*w):
#             maze[j][k] = min(maze[j][k], maze[j][i] + maze[i][k])

maze = floyd_warshall(maze)

# print(maze)
# print(maze[maze < INF])
print(int(max(maze[maze<INF])))