Amusing Numbers
Let us consider the set of integer numbers between 1 and N inclusive. Let us order them lexicographically (i. e. like in the vocabulary), for example, for N = 11 the order would be: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9.
Let us denote the position of the number K in this ordering as QN,K. For example, Q11,2 = 4. Given numbers K and M find the smallest N such that QN,K = M.
InputInput file contains two integer numbers K and M (1 ≤ K, M ≤ 10^9) separated by a space.
OutputIf such N that QN,K = M exists then write to the output file the smallest such N, otherwise write 0.
Input:
Output:
2 3Output:
11Input:
Output:
2 1Output:
0Input:
Output:
100000001 1000000000Output:
100000000888888879Input:
Output:
1000000000 11Output:
0Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.