import queue
import numpy as np
h,w=map(int,input().split())
table=[]

for i in range(h):
    line=input()
    table.append(line)
max_dis=0
for a in range(h):
    for b in range(w):
        if table[a][b]=="#":
            continue
        else:
            i=a
            j=b
            dp=[[0]*w for j_ in range(h)]
            q=queue.Queue()
            dp_set=set()
            q.put((i,j))
            while not q.empty():
                i,j=q.get()
                if (i-1,j) not in dp_set and 0<=i-1 and table[i-1][j]==".":
                    dp[i-1][j]=dp[i][j]+1
                    q.put((i-1,j))
                if (i,j-1) not in dp_set and 0<=j-1 and table[i][j-1]==".":
                    dp[i][j-1]=dp[i][j]+1
                    q.put((i,j-1))
                if (i+1,j) not in dp_set and i+1<=h-1 and table[i+1][j]==".":
                    dp[i+1][j]=dp[i][j]+1
                    q.put((i+1,j))
                if (i,j+1) not in dp_set and j+1<=w-1 and table[i][j+1]==".":
                    dp[i][j+1]=dp[i][j]+1    
                    q.put((i,j+1))
                dp_set.add((i,j))
            dp=np.array(dp)
            max_dis=max(np.max(dp),max_dis)
            
print(max_dis)
