from collections import deque

H, W = map(int, input().split())
maze = [input() for i in range(H)]
ans = 0
move = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for h in range(H):
    for w in range(W):
        if maze[h][w] == '#':
            continue
        queue = deque()
        max_depth = 0
        visited = [[False] * W for i in range(H)]
        queue.append((h, w, 0))
        while queue:
            i, j, depth = queue.popleft()
            max_depth = max(max_depth, depth)
            for di, dj in move:
                ni, nj = i+di, j+dj
                if 0 <= ni < H and 0 <= nj < W and maze[ni][nj] == '.' and not visited[ni][nj]:
                    queue.append((ni, nj, depth+1))
                    visited[ni][nj] = True
        ans = max(ans, max_depth)
print(ans)
