P2022 Interesting Numbers

Description

Consider the set of positive integers from $1$ to $N$. Arrange the elements of the set in lexicographical order; for example, when $N=11$, the order is: $1,10,11,2,3,4,5,6,7,8,9$. Define the position of $K$ among the $N$ numbers as $Q(N,K)$; for example, $Q(11,2)=4$. Now, given integers $K$ and $M$, find the smallest $N$ such that $Q(N,K)=M$.

Input Format

The input file contains a single line with two integers $K$ and $M$.

Output Format

Output a single line with the smallest $N$. If no such $N$ exists, output $0$.

Explanation/Hint

Constraints For $40\%$ of the testdata, $1 \le K, M \le 10^5$. For $100\%$ of the testdata, $1 \le K, M \le 10^9$. Translated by ChatGPT 5