import sys
from collections import *
INF = 500000
mod = 10**9+7

H, W = map(int, input().split())
f = [input() for i in range(H)]
es = defaultdict(lambda : INF)
for i in range(H):
    for j in range(W-1):
        if f[i][j] == '.' and f[i][j+1] == '.':
            es[((i, j), (i, j+1))] = 1
            es[((i, j+1), (i, j))] = 1
for i in range(H-1):
    for j in range(W):
        if f[i][j] == '.' and f[i+1][j] == '.':
            es[((i, j), (i+1, j))] = 1
            es[((i+1, j), (i, j))] = 1
V = []
for i in range(H):
    for j in range(W):
        if f[i][j] == '.':
            es[((i, j), (i, j))] = 0
            V.append((i, j))
for k in V:
    for i in V:
        for j in V:
            tmp = es[(i, k)] + es[(k, j)]
            if tmp < es[(i, j)]:
                es[(i, j)] = tmp
ans = 0
for i in V:
    for j in V:
        if ans < es[(i, j)]:
            ans = es[(i, j)]
print(ans)
