Y = [-1,0,1,0]; X = [0,-1,0,1]
H, W = gets.split.map(&:to_i)
areas = [] << Array.new(W+2, "@")
H.times do
  areas << ["@"] + gets.chomp.split('') + ["@"]
end
areas << Array.new(W+2, "@")
# areas.each do |area|
#   p area
# end
queue = []
rounds = [0]
1.upto(H) do |i|
  1.upto(W) do |j|
    if areas[i][j] == "#"
      queue.push([i, j, 0]) # "#"のマスを全てキューに格納
    end
  end
end
while !queue.empty?
  now = queue.shift
  rounds << now[2] if rounds[-1] < now[2]
  areas[now[0]][now[1]] = "#"
  4.times do |k|
    nexy = now[0] + Y[k]
    nexx = now[1] + X[k]
    if areas[nexy][nexx] == "."
      queue.push([nexy, nexx, now[2] + 1])
    end
  end
end
puts rounds.size - 1