
def bfs(start, maze):
    from collections import deque
    visited = {start}
    q = deque([(start, 0)])
    dmax = 0
    while q:
        pos, dist = q.popleft()
        dmax = max(dmax, dist)
        for dx, dy in [(0,1),(0,-1),(1,0),(-1,0)]:
            nx = pos[0] + dx
            ny = pos[1] + dy
            if (nx, ny) not in visited and 0 <= nx < len(maze) and 0 <= ny < len(maze[0]) and maze[nx][ny]==".":
                visited.add((nx, ny))
                q.append(((nx, ny), dist+1))
    return dmax


def main():
    H, W = [int(x) for x in input().split()]
    maze = [input() for _ in range(H)]
    starts = [(x, y) for x in range(H) for y in range(W)]
    ans = 0
    for pos in starts:
        ans = max(ans, bfs(pos, maze))
    print(ans)


if __name__ == '__main__':
    main()