from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
S=np.zeros_like(T,dtype=int) 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
        c=deque()    
        s=0
        c.append((i,j))
        #c.append(j)
        
        t=len(c)
        while t>0:
                s+=1
                t=len(c)
                for k in range(t):
                        m,n = c.popleft()
                        #n = c.popleft()
                        S[m][n]=s
                        for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                          if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                          if T[kk]==1:continue
                          if S[kk] == 0:
                            c.append(kk)
                            
                        
 
        #print(T)
        d = max(d,s)
        S=np.zeros_like(T,dtype=int)
        
print(d-2)