H, W = list(map(int, input().split()))

S = [eval(input()) for _ in range(H)]



N = W * H

E = [[0] * N  for _ in range(N)]



dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]



for i in range(H):

    for j in range(W):

        if S[i][j] == ".":

            for di, dj in dij:

                ni, nj = i + di, j + dj

                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":

                    E[W * i + j][W * ni + nj] = 1



from scipy.sparse.csgraph import floyd_warshall

A = floyd_warshall(E)

INF = float("inf")



print((int(max(max(a if a != INF else 0 for a in a) for a in A))))
INF = float("inf")



H, W = list(map(int, input().split()))

S = [eval(input()) for _ in range(H)]



N = W * H

E = [[INF] * N  for _ in range(N)]



dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]



for i in range(H):

    for j in range(W):

        if S[i][j] == ".":

            for di, dj in dij:

                ni, nj = i + di, j + dj

                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":

                    E[W * i + j][W * ni + nj] = 1



from scipy.sparse.csgraph import floyd_warshall

A = floyd_warshall(E)

INF = float("inf")



print((int(max(max(a if a != INF else 0 for a in a) for a in A))))

H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
N = W * H
E = [[0] * N for _ in range(N)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for di, dj in dij:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":
                    E[W * i + j][W * ni + nj] = 1
from scipy.sparse.csgraph import floyd_warshall

A = floyd_warshall(E)
INF = float("inf")
print((int(max(max(a if a != INF else 0 for a in a) for a in A))))

INF = float("inf")
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
N = W * H
E = [[INF] * N for _ in range(N)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for di, dj in dij:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":
                    E[W * i + j][W * ni + nj] = 1
from scipy.sparse.csgraph import floyd_warshall

A = floyd_warshall(E)
INF = float("inf")
print((int(max(max(a if a != INF else 0 for a in a) for a in A))))

+INF = float("inf") -E = [[0] * N for _ in range(N)] +E = [[INF] * N for _ in range(N)]