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)
    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]!='#'
            if dis[y,x]+1<dis[j,i] || dis[j,i]==-1
                dis[j,i]=dis[y,x]+1
                dfs(i,j,dis)
            end
        end
    end
    return dis
end

function main()
    ans=0
    for i in 1:h
        for j in 1:w
            if s[i][j]=='#'
                continue
            end
            dis=fill(-1,(h,w))
            dis[i,j]=0
            dfs(j,i,dis)
            res=findmax(dis)
            ans=max(ans,res[1])
        end
    end
    println(ans)
end
main()