from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))


def bfs(i, j):
    visited = [[False] * W for _ in range(H)]
    visited[i][j] = True
    que = deque([(i, j, 0)])

    while que:
        ci, cj, d = que.popleft()

        for di, dj in move:
            ni, nj = ci + di, cj + dj
            if not (0 <= ni < H and 0 <= nj < W) or visited[ni][nj]:
                continue
            if S[ni][nj] == '.':
                visited[ni][nj] = True
                que.append((ni, nj, d+1))

    return d


ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, bfs(i, j))
print(ans)
