#P2022. 有趣的数

有趣的数

Description

Consider the set of positive integers from 11 to NN. Arrange the elements of the set in lexicographical order; for example, when N=11N=11, the order is: 1,10,11,2,3,4,5,6,7,8,91,10,11,2,3,4,5,6,7,8,9.

Define the position of KK among the NN numbers as Q(N,K)Q(N,K); for example, Q(11,2)=4Q(11,2)=4. Now, given integers KK and MM, find the smallest NN such that Q(N,K)=MQ(N,K)=M.

Input Format

The input file contains a single line with two integers KK and MM.

Output Format

Output a single line with the smallest NN. If no such NN exists, output 00.

2 4

11

100000001 1000000000
100000000888888879

Hint

Constraints

For 40%40\% of the testdata, 1K,M1051 \le K, M \le 10^5.

For 100%100\% of the testdata, 1K,M1091 \le K, M \le 10^9.

Translated by ChatGPT 5