H, W = gets.split.map(&:to_i)
cell = H.times.map{gets.split("")}

painted = []
H.times do |h|
  W.times do |w|
    painted << [h, w, 0] if cell[h][w] == '#'
  end
end

ans = 0
until painted.empty?
  blackcell = painted.shift
  [[1, 0], [0, 1], [-1, 0], [0, -1]].each do |dy, dx|
    nh = blackcell[0] + dy
    nw = blackcell[1] + dx
    d = blackcell[2]
    if 0 <= nh and nh < H and 0 <= nw and nw < W and cell[nh][nw] == '.'
      cell[nh][nw] = '#'
      painted << [nh, nw, d + 1]
    end
    ans = d
  end
end
puts ans