You write out a list of numbers. For each digit i from 1 to 9, the list holds every positive integer whose decimal representation contains exactly Di copies of the digit i. The number of zeros is not restricted. You write the numbers in ascending order.
For example, if you write every number with two 1s and one 5, the list starts 115, 151, 511, 1015, 1051.
You are given N, the last number you wrote. The counts Di are the digit counts of N itself. Compute the next number in the list.