h,w = gets.split.map(&:to_i)
s = []
h.times{s << gets.chomp.split("")}

ans = 0
h.times do |x|
    w.times do |y|
        next if s[x][y] == "#"

        dp = Array.new(h){Array.new(w)}
        dp[x][y] = 0
        queue = [[x,y]]

        loop do
            sx, sy = queue.shift
            break if !sx || !sy

            if sx > 0 && s[sx-1][sy] != "#" && !dp[sx-1][sy] 
                dp[sx-1][sy] = dp[sx][sy] + 1
                queue << [sx-1,sy]
            end

            if sx < h-1 && s[sx+1][sy] != "#" && !dp[sx+1][sy] 
                dp[sx+1][sy] = dp[sx][sy] + 1
                queue << [sx+1,sy]
            end

            if sy > 0 && s[sx][sy-1] != "#" && !dp[sx][sy-1] 
                dp[sx][sy-1] = dp[sx][sy] + 1
                queue << [sx,sy-1]
            end

            if sy < w-1 && s[sx][sy+1] != "#" && !dp[sx][sy+1] 
                dp[sx][sy+1] = dp[sx][sy] + 1
                queue << [sx,sy+1]
            end
        end

        m = dp.map{|e| e.compact.max}.max
        ans = m if ans < m
    end
end

puts ans