# coding: utf-8
from collections import deque
def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    count = 0
    while queue:
        #ここでforループを回している
        for _ in range(len(queue)):
            coord = queue.popleft()
            visited[coord[0]][coord[1]] = 1
            if coord == [gy, gx]:
                return count
            for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                next_coord = [coord[0]+j, coord[1]+k]
                if next_coord[0] < 0 or next_coord[0] > H-1 or next_coord[1] < 0 or next_coord[1] > W-1:
                    continue
                if maze[next_coord[0]][next_coord[1]] == "." and \
                   visited[next_coord[0]][next_coord[1]] != 1:
                    queue.append(next_coord)
        count += 1


import sys
sys.setrecursionlimit(10**8)
H, W = map(int, input().split())
maze = []
for i in range(H):
    tmp = list(input())
    # tmp = input()
    maze.append(tmp[:])
# print(*maze, sep="\n")
# exit()
ans = -1
for sx in range(H):
    for sy in range(W):
        for ex in range(H):
            for ey in range(W):
                if maze[sx][sy] == "#" or maze[ex][ey] == "#":
                    continue
                if sx == ex and sy == ey:
                    continue
                # maze[ex][ey] = "g"
                top = [-1]
                visited = [[-1 for _ in range(W)] for _ in range(H)]
                # dfs(sx, sy, 0)
                tmp = bfs(maze, visited, sx, sy, ex, ey)
                ans = max(ans, tmp)
print(ans)