from collections import deque
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
ans=[]

for i in range(H):
    for j in range(W):
        c=0
        sy=i
        sx=j
        route=deque([(sy,sx,0)])
        while route:
            a,b,n=route.popleft()
            if 0<=a<=H-1 and 0<=b<=W-1:
                if S[a][b]=='.':
                    S[a][b]='#'
                    route.append((a+1,b,n+1))
                    route.append((a-1,b,n+1))
                    route.append((a,b+1,n+1))
                    route.append((a,b-1,n+1))
        ans.append(n-1)

print(max(ans))