import numpy as np
from scipy.sparse.csgraph import floyd_warshall
i8 = np.int64
i4 = np.int32
dot = 46

stdin = open(0).read().split(sep='\n', maxsplit=1)
H, W = map(int, stdin[0].split())
s = np.frombuffer(np.array(stdin[1]), dtype=i4).reshape(H, W+1)
s = np.vstack((s, np.zeros(W + 1, i4)))
g = np.zeros((H * W, H * W), i8)
for i in range(H):
    for j in range(W):
        if s[i, j] == dot:
            if s[i, j + 1] == dot:
                g[W * i + j, W * i + j + 1] = 1
                g[W * i + j + 1, W * i + j] = 1
            if s[i + 1, j] == dot:
                g[W * i + j, W * (i + 1) + j] = 1
                g[W * (i + 1) + j, W * i + j] = 1

dist_matrix = floyd_warshall(g)
print(int(np.max(dist_matrix[dist_matrix < 40])))