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

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

  if 0 <= x-1
    queue << [x-1, y, c+1] unless visited[y][x-1]
  end
  if x+1 < w
    queue << [x+1, y, c+1] unless visited[y][x+1]
  end

  if 0 <= y-1
    queue << [x, y-1, c+1] unless visited[y-1][x]
  end

  if y+1 < h
    queue << [x, y+1, c+1] unless visited[y+1][x]
  end
end

p max_distance
