parseline(str=readline()) = parse.(Int, split(str))
function MazeMaster()
    direction = [[-1, 0], [1, 0], [0, 1], [0, -1]]
    H, W = parseline()
    S = readlines() #Array{String, 1}
    ans = -1
    for h in 1:H
        length(S[h])==0 && continue
        score = fill(-1, H, W)
        for w in 1:W 
            S[h][w]=='#' && continue
            que = [[h, w]]
            score[h, w] = 0
            while !isempty(que)
                now = popfirst!(que)
                for d in direction
                    x, y = now + d
                    (!(1≤x≤H)||!(1≤y≤W)||(S[x][y]=='#')) && continue
                    score[x, y] < 0 && (push!(que, [x, y]); 
                        score[x, y] = score[now[1], now[2]] + 1)
                end
            end
            ans = max(ans, maximum(score))
        end
    end
    println(ans)
end
MazeMaster()