Acesrc is a famous mathematician at Nanjing University second to none. Playing with interesting numbers is his favorite. Today, he finds a manuscript when cleaning his room, which reads
... Let $f(d, n)$ denote the number of occurrences of digit $d$ in decimal representations of integers $1, 2, 3, \cdots, n$. The function has some fantastic properties ...
... Obviously, there exist some nonnegative integers $k$, such that $f(d, k) = k$, and I decide to call them $d$-good numbers ...
... I have found all $d$-good numbers not exceeding $10^{1000}$, but the paper is too small to write all these numbers ...
Acesrc quickly recollects all $d$-good numbers he found, and he tells Redsun a question about $d$-good numbers: what is the maximum $d$-good number no greater than $x$? However, Redsun is not good at mathematics, so he wants you to help him solve this problem.