h,w =map(int, input().split())
a =['#'*(w+2)] + ['#'+input()+'#' for i in range(h)]+['#'*(w+2)]
ans=0
for ii in range(h):
    for jj in range(w):
        for k in range(h):
            for l in range(w):
                ys, xs = ii+1, jj+1
                yg, xg = k+1, l+1
                
                if yg<ys or xg<xs:
                    continue
                    
                n=[(ys-1,xs-1)]
                route={n[0]:0}
                p=[[1,0],[0,1],[-1,0],[0,-1]]
                count=1
                while route.get((yg-1,xg-1),0)==0 and count != 100:
                    n2=[]
                    for i in n:
                        for j in p:
                            np=(i[0]+j[0],i[1]+j[1])
                            if a[np[0]][np[1]]=='.' and route.get(np,-1)==-1:
                                n2.append(np)
                                route[np]=count
                    n=n2
                    count+=1
                ans=max(ans,max(route.values()))
print(ans)
