
h = gets.to_i
@n = h.times.map{ gets.chomp.split('')}
@n_size = @n.size
@d = Array.new(@n_size).map{Array.new(@n_size, nil)}
@f = []

def s(x)
  0 <= x && x < @n_size
end

def f(x,y,i)
  if s(x+1) && s(y) && @d[x+1][y] == nil
    @f << [x+1,y]
    @d[x+1][y] = i
  end
  if s(x-1) && s(y) && @d[x-1][y] == nil
    @f << [x-1,y]
    @d[x-1][y] = i
  end
  if s(x) && s(y+1) && @d[x][y+1] == nil
    @f << [x,y+1]
    @d[x][y+1] = i
  end
  if s(x) && s(y-1) && @d[x][y-1] == nil
    @f << [x,y-1]
    @d[x][y-1] = i
  end
end

@n_size.times do |x|
  @n_size.times do |y|
    if @n[x][y] == "#"
      f(x,y,1)
      @d[x][y] = 0
    end
  end
end


while @f != []
  x, y = @f.shift
  f(x,y,@d[x][y]+1)
end

p @d.flatten.max
