# A happy new year, AtCoder !
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

myinf = 10 ** 9 + 7
tab_graph = [[myinf] * (H * W) for _ in range(H * W)]

for i in range(H):
    for j in range(W):
        for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if i + di < 0: continue
            if i + di >= H: continue
            if j + dj < 0: continue
            if j + dj >= W: continue
            # print("#", i, j, '->', i + di, j + dj)
            if S[i][j] == '#': continue
            #
            src = i * W + j
            dst = (i + di) * W + (j + dj)
            tab_graph[src][dst] = 1

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

G = csgraph_from_dense(tab_graph, null_value=myinf)
d = floyd_warshall(G)

# print("#", d)
ans = 0
for i in range(H * W):
    for j in range(H * W):
        if i == j: continue
        # print("##", i, j, d[i][j])
        if d[i][j] < myinf: ans = max(ans, int(d[i][j]))

print(ans)
