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

require "set"

def around(idx, h, w)
  i = idx / w
  j = idx % w
  res = []
  res << (i - 1) * w + j if i > 0
  res << (i + 1) * w + j if i < h - 1
  res << i * w + (j - 1) if j > 0
  res << i * w + (j + 1) if j < w - 1
  res
end

indexes = Set.new((0...(h * w)).to_a)
queue = Set.new
idx = 0
while (idx = a.index("#", idx))
  indexes.delete(idx)
  around(idx, h, w).each {|i| queue << i }
  idx += 1
end

cnt = 0
blacks = Set.new
until indexes.empty?
  cnt += 1
  indexes -= queue
  blacks += queue
  queue = queue.map {|i| around(i, h, w) }.flatten.to_set - blacks
end

puts cnt