H,W=map(int,input().split())
S=[]
for _ in range(H):
    S.append(list(input()))

from collections import deque

que=deque()
maxx=0

for i in range(H):
    for j in range(W):
        ans=[[100]*W for _ in range(H)]
        ans[i][j]=0
        que.append((i,j))
        while que:
            h,w=que.popleft()
            if h!=0 and S[h-1][w]==".":
                if ans[h-1][w]==100:
                    ans[h-1][w]=min(ans[h-1][w],ans[h][w]+1)
                    que.append((h-1,w))
            if h!=H-1 and S[h+1][w]==".":
                if ans[h+1][w]==100:
                    ans[h+1][w]=min(ans[h+1][w],ans[h][w]+1)
                    que.append((h+1,w))
            if w!=0 and S[h][w-1]==".":
                if ans[h][w-1]==100:
                    ans[h][w-1]=min(ans[h][w-1],ans[h][w]+1)
                    que.append((h,w-1))
            if w!=W-1 and S[h][w+1]==".":
                if ans[h][w+1]==100:
                    ans[h][w+1]=min(ans[h][w+1],ans[h][w]+1)
                    que.append((h,w+1))
            maxx=max(maxx,ans[h][w])
print(maxx)  