from collections import deque

INF = -1

sizeI, sizeJ = map(int, input().split())
a = [input().rstrip() for _ in range(sizeI)]

def bfs(startI, startJ, targetI, targetJ):
    dist = [[INF for _ in range(sizeJ)] for _ in range(sizeI)]
    dist[startI][startJ] = 0
    q = deque([(startI, startJ)])
    while q:
        i, j = q.pop()
        curDist = dist[i][j]
        if (i, j) == (targetI, targetJ):
            return curDist
        for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < sizeI and 0 <= nj < sizeJ and dist[ni][nj] == INF and a[ni][nj] == '.':
                dist[ni][nj] = 1 + curDist
                q.appendleft((ni, nj))
    raise Exception

points = []
for i in range(sizeI):
    for j in range(sizeJ):
        if a[i][j] == '.':
            points.append((i, j))
ret = 0
for i in range(len(points) - 1):
    for j in range(i + 1, len(points)):
        ret = max(ret, bfs(points[i][0], points[i][1], points[j][0], points[j][1]))
print(ret)