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):
        count=1
        n=[(ii,jj)]
        route={n[0]:0}
        p=[[1,0],[0,1],[-1,0],[0,-1]]
        while count != 100:
            route2 = route.copy()
            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
            if route == route2:
                break
        ans=max(ans,max(route.values()))
print(ans)