require 'pp'
H, W = gets.split.map &:to_i
S = []
H.times do 
    S << gets.chomp.chars.map { |c| c == ?# ? true : false }
end


def bfs(i, j)
    queue = [[i, j, 0]]
    visited = Array.new(H) { Array.new(W, false) }
    visited[i][j] = true
    steps = 0
    while !queue.empty? do
        x, y, count = queue.shift
        steps = count
        queue += [[[x + 1, H-1].min, y, count + 1], [[x - 1, 0].max, y, count + 1], [x, [y + 1, W-1].min, count + 1], [x, [y - 1, 0].max, count + 1]].reject{|a, b, c| visited[a][b] || S[a][b]}.each{|a, b, c| visited[a][b] = true}
    end
    return steps
end

ans = 0
for i in 0..H-1
    for j in 0..W-1
        next if S[i][j]
        ans = [ans, bfs(i, j)].max 
    end
end

p ans
