h,w=map(int,input().split())
l=set()
for i in range(h):
    t=input()
    for j in range(w):
        if t[j]==".":
            l.add((i,j))
ans=0
from collections import deque
for i,j in l:
    q=deque([(i,j,0)])
    s=set()
    while q:
        x,y,z=q.popleft()
        s.add((x,y))
        tf=True
        if (x+1,y) in l and (x+1,y) not in s:
            q.append((x+1,y,z+1))
            tf=False
        if (x-1,y) in l and (x-1,y) not in s:
            q.append((x-1,y,z+1))
            tf=False
        if (x,y+1) in l and (x,y+1) not in s:
            q.append((x,y+1,z+1))
            tf=False
        if (x,y-1) in l and (x,y-1) not in s:
            q.append((x,y-1,z+1))
            tf=False
        if tf:
            ans=max(ans,z)

print(ans)


    



