from collections import deque

INF = 10000

H, W = map(int, input().split())
Sss = ['#'*(W+2)] + ['#'+input()+'#' for _ in range(H)] + ['#'*(W+2)]

poss = []
for i in range(1, H+1):
    for j in range(1, W+1):
        if Sss[i][j] == '.':
            poss.append((i, j))

def bfsGridGraph(Sss, xSt, ySt, xEn, yEn, INF):
    dxys = [(-1,0), (1,0), (0,-1), (0,1)]
    distss = [[(INF if S != '#' else -1) for S in Ss] for Ss in Sss]
    distss[xSt][ySt] = 0
    Q = deque([(xSt, ySt)])
    while Q:
        x, y = Q.popleft()
        dist = distss[x][y]
        for dx, dy in dxys:
            x2, y2 = x+dx, y+dy
            if distss[x2][y2] == INF:
                distss[x2][y2] = dist + 1
                Q.append((x2, y2))
    return distss

N = len(poss)
ans = 0
for i in range(N):
    xSt, ySt = poss[i]
    for j in range(i+1, N):
        xEn, yEn = poss[j]
        distss = bfsGridGraph(Sss, xSt, ySt, xEn, yEn, INF)
        dist = distss[xEn][yEn]
        ans = max(ans, dist)

print(ans)
