h, w = gets.split.map(&:to_i)

a = Array.new(h) { gets.chomp }

visited = Array.new(h) { Array.new(w, false) }
# [x, y, cost]
queue = []

h.times do |y1|
  w.times do |x1|
    if a[y1][x1] == '#'
      queue << [x1, y1, 0]
    end
  end
end

max_distance = 0

while !queue.empty?
  x, y, c = queue.shift

  if visited[y][x]
#    puts "#{[x, y, c]} is already visited"
    next
  else
#    puts "#{[x, y, c]} is new place"
  end

  visited[y][x] = true

  max_distance = c if max_distance < c
  visited[y][x] = true

  [[x, y-1], [x, y+1], [x+1, y], [x-1, y]].each do |x2, y2|
    if 0 <= x2 && x2 < w && 0 <= y2 && y2 < h
#      puts "add #{[x2, y2, c+1]}"
      queue << [x2, y2, c+1]
    end
  end
end

p max_distance
