 H, W = gets.chomp.split.map(&:to_i)
A = []
H.times do
  A << gets.chomp
end

# p [H, W]
# p A

queue = []
0.upto(H-1).each do |h|
  0.upto(W-1).each do |w|
    c = A[h][w]
    if c == '#'
      queue.push([h, w, 0])
    end
  end
end

max = 0
while (queue.size > 0) 
  h, w, d = queue.shift
  if (h > 0) && A[h-1][w] != '#'
    A[h-1][w] = '#'
    queue.push([h-1, w, d + 1])
    max = [max, d + 1].max
  end
  if (h < H-1) && A[h+1][w] != '#'
    A[h+1][w] = '#'
    queue.push([h+1, w, d + 1])
    max = [max, d + 1].max
  end
  if (w > 0) && A[h][w-1] != '#' 
    A[h][w-1] = '#'
    queue.push([h, w-1, d + 1])
    max = [max, d + 1].max
  end
  if (w < W-1) && A[h][w+1] != '#' 
    A[h][w+1] = '#'
    queue.push([h, w+1, d + 1])
    max = [max, d + 1].max
  end
end

p max
