from collections import deque
from itertools import product
H,W = map(int,input().split())

S = ["#"*(W+2)]
for i in range(H):
    S.append("#"+ input() + "#")
S.append("#"*(W+2))

H += 2
W += 2

max_dist = 0
for sy,sx in product(range(1,H),range(1,W)):
    dist = [[H+W+1]*W for i in range(H)]
    if S[sy][sx] == "#":
        continue
    dq = deque([(sy,sx)])
    dist[sy][sx] = 0
    while dq:
        py,px = dq.popleft()
        for ny, nx in [(py+1,px),(py-1,px),(py,px+1),(py,px-1)]:
            if S[ny][nx] == "#":
                continue
            if dist[ny][nx] > dist[py][px] + 1:
                dist[ny][nx] = dist[py][px] + 1
                max_dist = max(max_dist, dist[ny][nx])
                dq.append((ny,nx))

print(max_dist)








