def min_dist_to_black(map, i0, j0, h, w)
  visited = {}
  queue = []
  queue.push([i0, j0, 0])

  until queue.empty?
    i, j, d = queue.shift
    visited[[i,j]] = true
    if map[i][j] == '#'
      return d
    else
      -1.upto(1) do |di|
        -1.upto(1) do |dj|
          next unless di * dj == 0
          if (i+di).between?(0,h-1) && (j+dj).between?(0,w-1) &&
             !visited.has_key?([i+di,j+dj])
            queue.push([i+di, j+dj, d+1])
          end
        end
      end
    end
  end
  fail
end

h, w = gets.split.map(&:to_i)

map = h.times.map {
  gets.chomp.chars
}

max = -Float::INFINITY
0.upto(h-1) do |i|
  0.upto(w-1) do |j|
    map[i][j] == '.'
    tmp = min_dist_to_black(map, i, j, h, w)
    max = [max,tmp].max
  end
end

puts max
