h,w = gets.split.map(&:to_i)

if h == 1 and w == 1
  puts 0
else
  dmap = Hash.new{ |s,k| s[k] = [100000000]*w }
  black = []
  h.times do |hi|
    str = gets.chomp
    w.times do |wi|
      if str[wi] == '#'
        black.push([hi, wi])
      end
    end
  end

  step = 0

  while true
    if black.size == 0
      break
    end
    n = []

    black.each do |hb,wb|
      if step < dmap[hb][wb]
        dmap[hb][wb] = step
        n << [hb-1,wb] if hb > 0
        n << [hb+1,wb] if hb < h - 1 
        n << [hb,wb-1] if wb > 0
        n << [hb,wb+1] if wb < w - 1 
      end
    end
    black = n
    step += 1
  end

  puts step-2
end
