from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

H, W = map(int, input().split())
# Inf = 10**9

S = [input() for i in range(H)]
dis = [[0]*(H*W) for i in range(H*W)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        if i - 1 >= 0 and S[i-1][j] != "#":
            dis[i*W+j][(i-1)*W+j] = 1
        if i + 1 < H and S[i+1][j] != "#":
            dis[i*W+j][(i+1)*W+j] = 1
        if j - 1 >= 0 and S[i][j-1] != "#":
            dis[i*W+j][i*W+j-1] = 1
        if j + 1 < H and S[i][j+1] != "#":
            dis[i*W+j][i*W+j+1] = 1

g = floyd_warshall(csgraph_from_dense(dis))

max_ans = 0
for i in range(H*W):
    for j in range(H*W):
        if g[i][j] > max_ans and g[i][j] != float("inf"):
            max_ans = g[i][j]

print(int(max_ans))