H, W = gets.split.map(&:to_i)
field = H.times.map { gets.chomp.split(//) }

count = 0
head = []
field.each_with_index do |e, i|
  e.each_with_index do |e, j|
    if e == '#'
      head << [i, j]
      field[i][j] = '.'
    end
  end
end
count = -1
until head.empty?
  head_new = []
  res = false
  head.each do |i, j|
    next if i < 0 || H <= i || j < 0 || W <= j
    next if field[i][j] != '.'
    res = true
    field[i][j] = '#'
    head_new << [i, j - 1]
    head_new << [i, j + 1]
    head_new << [i - 1, j]
    head_new << [i + 1, j]
  end
  head = head_new
  count += 1 if res
end

puts count
