from collections import deque
import sys
from collections import defaultdict
input = sys.stdin.readline
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]

INF = 10 ** 9
n = H * W
d =[[INF for _ in range(n)] for _ in range(n)]
go = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for x in range(W):
    for y in range(H):
        for temp in go:
            gx,gy = temp
            nx = x + gx
            ny = y + gy
            if 0<= nx < W and 0<= ny < H and C[ny][nx] != "#":
                d[ny * W + nx][y * W + x] = 1
                d[y * W + x] [ny * W + nx]= 1
for i in range(n):
    d[i][i] = 0
    #d[i][j]: iからjへの最短距離
for k in range(n):
    for i in range(n):
        for j in range(n):
            if C[i//W][i%W] != "#" and C[j//W][j%W] != "#" and C[k//W][k%W] != "#":
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
ans = d
# print(ans)
x  = 0
for temp in ans:
    for k in temp:
        if k != INF:
            if k > x:
                x = k
print(x)

