import numpy as np


HEIGHT, WIDTH = map(int, input().split())
S = [input() for _ in range(HEIGHT)]
M = np.array([[0 if char == "." else -1 for char in row] for row in S], dtype=np.int64)


def bfs(i, j):
    for v in np.array([[1, 0], [0, 1]]):
        for flag in [1, -1]:
            di, dj = v * flag
            new_i, new_j = i + di, j + dj
            if (
                0 <= new_i < HEIGHT
                and 0 <= new_j < WIDTH
                and (new_i, new_j) != START
                and MM[new_i, new_j] == 0
            ):
                MM[new_i, new_j] = MM[i, j] + 1
                STACK.append((new_i, new_j))


ANS = 0
for i in range(HEIGHT):
    for j in range(WIDTH):
        if M[i, j] == 0:
            MM = M.ravel().copy().reshape(HEIGHT, WIDTH)
            START = (i, j)
            STACK = [START]
            while STACK:
                bfs(*STACK.pop(0))
            ANS = max(ANS, MM.max())
print(ANS)
