from collections import deque
h, w = map(int, input().split())

maze = [list(input()) for _ in range(h)]
directions = [
    [0, 1],
    [0, -1],
    [1, 0],
    [-1, 0]
]

def bfs(start, goal):
    visited = [[False] * w for _ in range(h)]
    que = deque([start + (0,)])

    max_cnt = -1
    while que:
        y, x, cnt = que.popleft()
        if 0 <= x < w and 0 <= y < h and maze[y][x] == '.' and not visited[y][x]:
            max_cnt = max(cnt, max_cnt)
            visited[y][x] = cnt + 1
            for dy, dx in directions:
                que.append((y + dy, x + dx, visited[y][x]))
    # print("\n".join([" ".join(map(str, v)) for v in visited]))
    return max_cnt

ans = 0
for sx in range(w):
    for sy in range(h):
        for gx in range(w):
            for gy in range(h):
                ans = max(ans, bfs((sy, sx), (gy, gx)))
print(ans)
