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

def process(a, h, w)
  b = a.map(&:dup)
  h.times do |i|
    j = 0
    while (j = a[i].index("#", j))
      b[i][j - 1] = "#" if j > 0
      b[i][j + 1] = "#" if j < w - 1
      b[i - 1][j] = "#" if i > 0
      b[i + 1][j] = "#" if i < h - 1
      j += 1
    end
  end
  b
end

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

puts cnt
