r, c = gets.split.map(&:to_i)

maze = []
queue = []
(0..r-1).each do |rr|
  line = gets.chomp
  line.each_char.each_with_index { |c, cc|
    queue << [rr, cc] if c == '#'
  }
  maze << line.split('').map{ |e| e=='#'? 0 : nil }
end

cnt = nil
until queue.empty?
  qx, qy = queue.shift
  cnt = maze[qx][qy].to_i + 1

  if qx + 1 < r && maze[qx+1][qy].nil?
    maze[qx+1][qy] = cnt
    queue << [qx+1, qy]
  end

  if qx > 0 && maze[qx-1][qy].nil?
    maze[qx-1][qy] = cnt
    queue << [qx-1, qy]
  end

  if qy + 1 < c && maze[qx][qy+1].nil?
    maze[qx][qy+1] = cnt
    queue << [qx, qy+1]
  end

  if qy > 0 && maze[qx][qy-1].nil?
    maze[qx][qy-1] = cnt
    queue << [qx, qy-1]
  end
end

p cnt - 1
