H, W = gets.split.map(&:to_i)
head = []
H.times do |i|
  gets.each_char.with_index do |c, j|
    if c == '#'
      head << i * W + j
    end
  end
end
field = Array.new(H * W)

count = -1
until head.empty?
  head_new = []
  res = false
  head.each do |ij|
    i = ij / W
    j = ij % W
    next if field[ij]
    res = true
    field[ij] = 0
    head_new << i * W + j - 1 if 0 < j && field[i * W + j - 1].nil?
    head_new << i * W + j + 1 if j < W - 1 && field[i * W + j + 1].nil?
    head_new << (i - 1) * W + j if 0 < i && field[(i - 1) * W + j].nil?
    head_new << (i + 1) * W + j if i < H - 1 && field[(i + 1) * W + j].nil?
  end
  head = head_new
  count += 1 if res
end

puts count
