# coding: utf-8
import sys
sys.setrecursionlimit(10**8)
H, W = map(int, input().split())
maze = []
for i in range(H):
    tmp = list(input())
    # for j in range(W):
    #     if tmp[j] == ".":
    #         tmp[j] = 1
    #     else:
    #         tmp[j] = 0
    maze.append(tmp[:])
# print(*maze, sep="\n")
# exit()
def dfs(i, j, cnt):
    if i < 0 or j < 0 or i > H-1 or j > W-1 or maze[i][j] == "#" or visited[i][j]:
        # top.append(cnt)
        return
    if maze[i][j] == "g":
        top.append(cnt)
        top[0] = max(top[0], cnt)
    
    visited[i][j] = True
    cnt += 1
    dfs(i+1, j, cnt)
    dfs(i-1, j, cnt)
    dfs(i, j+1, cnt)
    dfs(i, j-1, cnt)

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 = [[False for _ in range(W)] for _ in range(H)]
                dfs(sx, sy, 0)
                # print(top)
                maze[ex][ey] = "."
                # print(top)
                if top[0] == -1:
                    continue
                ans = max(ans, top[0])
print(ans)