from collections import deque
import numpy as np
 
def chk_route(c):
    global H,W,T
    ans=[]
    if c[0] != H-1:
        if T[c[0]+1][c[1]]==0:
            ans+=[c[0]+1,c[1]]
    if c[0] != 0:
        if T[c[0]-1][c[1]]==0:
            ans+=[c[0]-1,c[1]] 
    if c[1] != W-1:
        if T[c[0]][c[1]+1]==0:
            ans+=[c[0],c[1]+1]
 
    if c[1] != 0:
        if T[c[0]][c[1]-1]==0:
            ans+=[c[0],c[1]-1]

    return ans
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),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)
        c.append(j)
        T=B.copy()
        t=len(c)//2

        while t>0:
                s+=1
                t=len(c)//2
                for k in range(t):T[c[0+k*2]][c[1+k*2]]=s
                for k in range(t):
                        c += (chk_route([c.popleft(),c.popleft()]))
                
        #print(T)
        d = max(d,s)
         
print(d-2)