h, w = gets.chomp.split(" ").map(&:to_i)
a = ""
h.times { a.concat(gets.chomp) }

require "set"

def process2(a, h, w)
  idx = 0
  blacks = Set.new
  while (idx = a.index(".", idx))
    i = idx / w
    j = idx % w
    if (i > 0     && a[(i-1)*w+j] == "#") ||
       (i < h - 1 && a[(i+1)*w+j] == "#") ||
       (j > 0     && a[i*w+(j-1)] == "#") ||
       (j < w - 1 && a[i*w+(j+1)] == "#")
      blacks << [i, j]
    end
    idx += 1
  end
  blacks.each { |i, j| a[i * w + j] = "#" }
  a
end

cnt = 0
while a.index(".")
  cnt += 1
  a = process2(a, h, w)
end

puts cnt
