from collections import deque
h,w=map(int,input().split())
a=[input() for _ in range(h)]
ans=0
for y in range(h):
    for x in range(w):
        b=[[0]*w for _ in range(h)]
        if a[y][x]=="#":
            break
        now=deque([(y,x)])
        while len(now)!=0:
            Y,X=now.popleft()
            for i,j in [[0,1],[0,-1],[1,0],[-1,0]]:
                if 0<=Y+i<=h-1 and 0<=X+j<=w-1:
                    if a[Y+i][X+j]=="." and b[Y+i][X+j]==0 and (x!=X+j and y!=Y+j):
                        b[Y+i][X+j]=b[Y][X]+1
                        now.append((Y+i,X+j))
        c=0                
        for i in b:
            d=max(i)
            c=max(d,c)
        ans=max(ans,c)     
print(ans)