parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

h,w=parseMap(split(readline()))
s=[chomp(readline()) for i in 1:h]
function dfs(x,y,dis)
    if !(0<x<w+1 && 0<y<h+1 && s[y][x]!='#')
        return 0
    end
    for (i,j) in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
        if 0<i<w+1 && 0<j<h+1 && s[j][i]!='#' && dis[y,x]+1<dis[j,i]
            dis[j,i]=dis[y,x]+1
            dfs(i,j,dis)
        end
    end
    return dis
end
function main()
    ans=0
    for i in 1:h
        for j in 1:w
            dis=fill(10^9,(h,w))
            dis[i,j]=0
            dfs(j,i,dis)
            res=0
            for k in 1:h,l in 1:w
                if dis[k,l]<10^9
                    res=max(res,dis[k,l])
                end
            end
            ans=max(ans,res)
        end
    end
    println(ans)
end
main()