H, W = gets.split(' ').map(&:to_i)
map = Array.new(H)
lines = Array.new(H)
blacks = []
H.times do |h|
  line = gets
  map[h] = Array.new(W,0)
  index = 0
  while(index = line.index('#', index)) do
    map[h][index] = 1
    blacks.push([h, index, 2])
    index += 1
  end
end
result = 0
dxy = [[0,1],[0,-1],[1,0],[-1,0]]
while(q = blacks.shift) do
  h, w, dis = q
  dxy.each do |dh,dw|
    next if h+dh < 0 || h+dh >= H || w+dw < 0 || w+dw >= W
    next if map[h+dh][w+dw] > 0
    y, x = h+dh, w+dw
    map[y][x] = dis
    blacks.push [y,x, dis + 1]
    result = [result, dis].max
  end
end
puts (result - 1)