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):
        sy=i
        sx=j
        if S[i][j]=='#':
            continue
        for k in range(H):
            for l in range(W):
                ey=k
                ex=l
                if S[k][l]=='#':
                    continue
                route=deque([(sy,sx,0)])
                while route:
                    a,b,n=route.popleft()
                    if a==ey and b==ex:
                        ans.append(n)
                        break
                    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))

print(max(ans))