from collections import deque
import numpy as np
import copy

def bfs(maze, visited, sy, sx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 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
                queue.append([new_y, new_x])
    return visited

H, W = map(int, input().split())
MAZE = ["#" + input() + "#" for _ in range(H)]
MAZE.insert(0,"#"*(W+2))
MAZE.append("#"*(W+2))
ans = 0
visit = [[-1]*(W+2) for _ in range(H+2)]
for i in range(H + 2):
    for j in range(W + 2):
        if MAZE[i][j] == "#":
            visit[i][j] = 0
for i in range(1, H + 1):
    for j in range(1, W + 1):
        visited = copy.deepcopy(visit)
        tmp = np.max(bfs(MAZE, visited, i, j))
        ans = max(ans, tmp)
print(ans)
