h, w = gets.split(" ").map(&:to_i)
arr = []
pts = []
h.times do |hi|
  wi = 0
  gets.each_char do |c|
    n = (c == "." ? 0 : 1)
    pts << [hi, wi]
    arr << n
    wi += 1
  end
end

count = 0
while pts.length > 0
  count += 1
  new_pts = []
  pts.each do |hi, wi|
    (-1..1).each do |hh|
      (-1..1).each do |ww|
        next if hh == 0 && ww == 0
        next if (hh + ww) % 2 == 0
        p_h = hi + hh
        p_w = wi + ww
        next if p_h < 0 || p_h >= h
        next if p_w < 0 || p_w >= w
        next if arr[p_h][p_w] == 0
        arr[p_h][p_w] = 1
        new_pts << [p_h, p_w]
      end
    end
  end
  pts = new_pts.uniq
end

puts count