from collections import deque

def bfs(maze, visited, sy, sx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    ans=0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x]==-1:
                visited[new_y][new_x]=visited[y][x]+1
                ans=max(ans,visited[new_y][new_x])
                queue.append([new_y,new_x])
    return ans
    
def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="#"+maze[i]+"#"
    maze.appendleft("#"*(w+2))
    maze.append("#"*(w+2))
    return list(maze)
    
h,w=map(int,input().split())
maze=[input() for _ in range(h)]
maze=make_wall(maze,h,w)
ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        visited=[[-1]*(w+2) for _ in range(h+2)]
        tmp=bfs(maze, visited, i, j)
        ans=max(ans,tmp)
print(ans)