import queue

h,w=map(int,input().split())

s=[]
for i in range(h):
    s.append(input())

ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        qij=queue.Queue()
        qij.put([i,j])
        lis=[[0 for _ in range(w)] for _ in range(h)]
        check=[[0 for _ in range(w)] for _ in range(h)]
        check[i][j]=1
        while not qij.empty():
            ci,cj=qij.get()
            for a,b in [[ci+1,cj],[ci-1,cj],[ci,cj+1],[ci,cj-1]]:
                if 0<=a<=h-1 and 0<=b<=w-1 and s[a][b]=="." and check[a][b]==0:
                    lis[a][b]=lis[ci][cj]+1
                    qij.put([a,b])
                    check[a][b]=1
        ans=max(ans,max(max(lis)))
        
print(ans)