height, width = gets.split.map(&:to_i)
squares = Array.new(height) {Array.new(width, 0)}
queue = []

height.times do |h|
  gets.split('').each_with_index do |e, w|
    if e == '#'
      queue << h * width + w
      squares[h][w] = 1
    end
  end
end

n_step = 0

while (q = queue.shift)

  h, w = q.divmod(width)
  n_step = squares[h][w]

  if h + 1 < height && squares[hh = h + 1][w] == 0
    squares[hh][w] = n_step + 1
    queue << hh * width + w
  end

  if 0 <= h - 1 && squares[hh = h - 1][w] == 0
    squares[hh][w] = n_step + 1
    queue << hh * width + w
  end

  if w + 1 < width && squares[h][ww = w + 1] == 0
    squares[h][ww] = n_step + 1
    queue << h * width + ww
  end

  if 0 <= w - 1 && squares[h][ww = w - 1] == 0
    squares[h][ww] = n_step + 1
    queue << h * width + ww
  end
end

puts n_step - 1

