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
    blacks << [i - 1, j] if i > 0
    blacks << [i + 1, j] if i < h - 1
    blacks << [i, j - 1] if j > 0
    blacks << [i, j + 1] if j < w - 1
    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
