local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
List = {}
function List.new()
    return setmetatable({first = 0, last = -1}, {__index = List})
end

function List.clone(origin)
    local child = List.new()
    for k,v in pairs(origin) do
        child[k] = v
    end
    return child
end

function List:count()
    return self.last - (self.first - 1)
end

function List:pushleft(value)
    local first = self.first - 1
    self.first = first
    self[first] = value
end

function List:popright()
    local last = self.last
    if self.first > last then error("list is empty") end
    local value = self[last]
    self[last] = nil -- to allow garbage collection
    self.last = last - 1
    return value
end
----
local H, W = read.nnl()
local S = {}
for i=1,H do
    S[i] = read.l():totable()
end
local function bfs(i1, j1)
    if S[i1][j1] ~= '.' then
        return -1
    end
    local seen = {}
    for i=1,H do
        seen[i] = {}
    end
    local q = List.new()
    q:pushleft({i1, j1, 0})
    seen[i1][j1] = true
    local dmax = 0
    while q:count() > 0 do
        local i, j, d = table.unpack(q:popright())
        local function checkdo(newi, newj)
            if newi >= 1 and newi <= H then
                if not seen[newi][newj] and S[newi][newj] == '.' then
                    q:pushleft({newi, newj, d+1})
                    dmax = math.max(dmax, d+1)
                    seen[newi][newj] = true
                end
            end
        end
        checkdo(i+1,j)
        checkdo(i-1,j)
        checkdo(i,j+1)
        checkdo(i,j-1)
    end
    return dmax
end
local ans = 0
for i=1,H do
    for j=1,W do
        ans = math.max(ans, bfs(i, j))
    end
end
print(ans)
